mirror of
https://github.com/cupcakearmy/occulto.git
synced 2024-11-01 06:04:17 +01:00
Nicco
56a8103582
* rewrite * testing worklflow * sprcify version * config stuff * add hash as buffer * delete docs * use typedarray everywhere and docs * readme * aes * cleanup * rsa * testing with playwright * fix playwright * readme * docs * update deps * use headless * add prepublish * build pipeline * move types up * move types up * add types legacy * packaging * versions bump * cleanup * maybe this time * drop support for commonjs * version bump * cleanup
42 lines
1.5 KiB
JavaScript
42 lines
1.5 KiB
JavaScript
import { Bytes, RSA } from '../dist/index.js'
|
|
import { Promises } from './utils.js'
|
|
import { Precomputed } from './values.js'
|
|
|
|
describe('RSA', () => {
|
|
describe('Generate keys', function () {
|
|
this.timeout(5_000)
|
|
|
|
it('Should be able to generate a keypair', async () => {
|
|
await RSA.generateKeyPair()
|
|
})
|
|
it('Should be able to generate a keypair with 2048bit', async () => {
|
|
await RSA.generateKeyPair(2048)
|
|
})
|
|
it('Should be able to generate a keypair with 4096bit', async () => {
|
|
await RSA.generateKeyPair(4096)
|
|
})
|
|
it('Should not be able to generate a key below 2048bit', async () => {
|
|
await Promises.reject(() => RSA.generateKeyPair(1024))
|
|
})
|
|
it('Should not be able to generate a key below 2048bit', async () => {
|
|
await Promises.reject(() => RSA.generateKeyPair(-1))
|
|
})
|
|
})
|
|
|
|
describe('Encryption', () => {
|
|
for (const message of Object.values(Precomputed.Crypto.Messages)) {
|
|
it(`Should be able to encrypt and decrypt "${message.slice(0, 8)}..."`, async () => {
|
|
const pair = await RSA.generateKeyPair(2 ** 11)
|
|
const bytes = Bytes.encode(message)
|
|
try {
|
|
const encrypted = await RSA.encrypt(bytes, pair.public)
|
|
chai.expect.fail('Should have thrown error')
|
|
const decrypted = await RSA.decrypt(encrypted, pair.private)
|
|
chai.expect(decrypted).to.be.deep.equal(bytes)
|
|
chai.expect(message).to.be.equal(Bytes.decode(decrypted))
|
|
} catch {}
|
|
})
|
|
}
|
|
})
|
|
})
|