mirror of
https://github.com/cupcakearmy/occulto.git
synced 2024-12-22 05:26:28 +00:00
aes testing
This commit is contained in:
parent
8397b7fc26
commit
f2f8607c39
@ -2,27 +2,33 @@ import { AES, Bytes, Hashes, Hex } from '../dist/index.js'
|
|||||||
import { Precomputed } from './values.js'
|
import { Precomputed } from './values.js'
|
||||||
|
|
||||||
describe('AES', () => {
|
describe('AES', () => {
|
||||||
it('Basic API', async () => {
|
for (const keySize of [128, 192, 256]) {
|
||||||
const message = Precomputed.Crypto.Messages.nietzscheIpsum
|
describe('Key Size: ' + keySize, () => {
|
||||||
const data = Bytes.encode(message)
|
for (const message of Object.values(Precomputed.Crypto.Messages)) {
|
||||||
const [key] = await AES.derive('foo', {
|
describe(`Message: ${message.slice(0, 8)}...`, () => {
|
||||||
name: 'PBKDF2',
|
it('Basic API', async () => {
|
||||||
hash: Hashes.SHA_512,
|
const data = Bytes.encode(message)
|
||||||
iterations: 1000,
|
const [key] = await AES.derive('foo', {
|
||||||
length: 256,
|
name: 'PBKDF2',
|
||||||
salt: Hex.decode(Precomputed.Crypto.Bytes[16]),
|
hash: Hashes.SHA_512,
|
||||||
})
|
iterations: 1000,
|
||||||
const ciphertext = await AES.encrypt(data, key, AES.Modes.GCM)
|
length: keySize,
|
||||||
const plaintext = await AES.decrypt(ciphertext, key)
|
salt: Hex.decode(Precomputed.Crypto.Bytes[16]),
|
||||||
chai.expect(data).to.be.deep.equal(plaintext)
|
})
|
||||||
chai.expect(message).to.be.equal(Bytes.decode(plaintext))
|
const ciphertext = await AES.encrypt(data, key, AES.Modes.GCM)
|
||||||
})
|
const plaintext = await AES.decrypt(ciphertext, key)
|
||||||
|
chai.expect(data).to.be.deep.equal(plaintext)
|
||||||
|
chai.expect(message).to.be.equal(Bytes.decode(plaintext))
|
||||||
|
})
|
||||||
|
|
||||||
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)
|
})
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
@ -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.',
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user