mirror of
https://github.com/cupcakearmy/occulto.git
synced 2025-12-07 20:54:59 +00:00
add generate key
This commit is contained in:
@@ -2,11 +2,11 @@ import { AES, Bytes, Hashes, Hex } from '../dist/index.js'
|
||||
import { Precomputed } from './values.js'
|
||||
|
||||
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 () => {
|
||||
for (const message of Object.values(Precomputed.Crypto.Messages)) {
|
||||
describe(`Message: ${message.slice(0, 8)}...`, () => {
|
||||
describe('Basic API', () => {
|
||||
for (const keySize of [128, 256]) {
|
||||
it('Key Size: ' + keySize, async () => {
|
||||
const data = Bytes.encode(message)
|
||||
const [key] = await AES.derive('foo', {
|
||||
name: 'PBKDF2',
|
||||
@@ -20,15 +20,24 @@ describe('AES', () => {
|
||||
chai.expect(data).to.be.deep.equal(plaintext)
|
||||
chai.expect(message).to.be.equal(Bytes.decode(plaintext))
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('Easy API', async () => {
|
||||
const password = 'foobar'
|
||||
const encrypted = await AES.encryptEasy(message, password)
|
||||
const decrypted = await AES.decryptEasy(encrypted, password)
|
||||
chai.expect(message).to.be.equal(decrypted)
|
||||
})
|
||||
})
|
||||
}
|
||||
it('Generated Key', async () => {
|
||||
const key = await AES.generateKey()
|
||||
const data = Bytes.encode(message)
|
||||
const ciphertext = await AES.encrypt(data, key)
|
||||
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 () => {
|
||||
const password = 'foobar'
|
||||
const encrypted = await AES.encryptEasy(message, password)
|
||||
const decrypted = await AES.decryptEasy(encrypted, password)
|
||||
chai.expect(message).to.be.equal(decrypted)
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -11,8 +11,11 @@ export const Precomputed = {
|
||||
'hello world': '68656c6c6f20776f726c64',
|
||||
},
|
||||
Bytes: {
|
||||
test: [0x74, 0x65, 0x73, 0x74],
|
||||
occulto: [0x6f, 0x63, 0x63, 0x75, 0x6c, 0x74, 0x6f],
|
||||
test: new Uint8Array([0x74, 0x65, 0x73, 0x74]),
|
||||
occulto: new Uint8Array([0x6f, 0x63, 0x63, 0x75, 0x6c, 0x74, 0x6f]),
|
||||
'entropy is king': new Uint8Array([
|
||||
0x65, 0x6e, 0x74, 0x72, 0x6f, 0x70, 0x79, 0x20, 0x69, 0x73, 0x20, 0x6b, 0x69, 0x6e, 0x67,
|
||||
]),
|
||||
},
|
||||
},
|
||||
Hash: {
|
||||
|
||||
Reference in New Issue
Block a user