aes testing

This commit is contained in:
cupcakearmy 2022-10-18 17:37:04 +02:00
parent 8397b7fc26
commit f2f8607c39
No known key found for this signature in database
GPG Key ID: 3235314B4D31232F
2 changed files with 30 additions and 22 deletions

View File

@ -2,14 +2,17 @@ import { AES, Bytes, Hashes, Hex } from '../dist/index.js'
import { Precomputed } from './values.js' import { Precomputed } from './values.js'
describe('AES', () => { describe('AES', () => {
for (const keySize of [128, 192, 256]) {
describe('Key Size: ' + keySize, () => {
for (const message of Object.values(Precomputed.Crypto.Messages)) {
describe(`Message: ${message.slice(0, 8)}...`, () => {
it('Basic API', async () => { it('Basic API', async () => {
const message = Precomputed.Crypto.Messages.nietzscheIpsum
const data = Bytes.encode(message) const data = Bytes.encode(message)
const [key] = await AES.derive('foo', { const [key] = await AES.derive('foo', {
name: 'PBKDF2', name: 'PBKDF2',
hash: Hashes.SHA_512, hash: Hashes.SHA_512,
iterations: 1000, iterations: 1000,
length: 256, length: keySize,
salt: Hex.decode(Precomputed.Crypto.Bytes[16]), salt: Hex.decode(Precomputed.Crypto.Bytes[16]),
}) })
const ciphertext = await AES.encrypt(data, key, AES.Modes.GCM) const ciphertext = await AES.encrypt(data, key, AES.Modes.GCM)
@ -19,10 +22,13 @@ describe('AES', () => {
}) })
it('Easy API', async () => { it('Easy API', async () => {
const message = Precomputed.Crypto.Messages.nietzscheIpsum
const password = 'foobar' const password = 'foobar'
const encrypted = await AES.encryptEasy(message, password) const encrypted = await AES.encryptEasy(message, password)
const decrypted = await AES.decryptEasy(encrypted, password) const decrypted = await AES.decryptEasy(encrypted, password)
chai.expect(message).to.be.equal(decrypted) chai.expect(message).to.be.equal(decrypted)
}) })
}) })
}
})
}
})

View File

@ -48,6 +48,8 @@ export const Precomputed = {
}, },
Messages: { Messages: {
test: 'test', test: 'test',
occulto: 'occulto',
weird: 'Some 🃏 weird 🃏 text',
nietzscheIpsum: nietzscheIpsum:
'Marvelous intentions joy deceptions overcome sexuality spirit against. Selfish of marvelous play dead war snare eternal-return ultimate. Reason aversion suicide.', 'Marvelous intentions joy deceptions overcome sexuality spirit against. Selfish of marvelous play dead war snare eternal-return ultimate. Reason aversion suicide.',
}, },