feat: use webcrypto in favor of node-forge

BREAKING CHANGE: generateKeyPair is now async
This commit is contained in:
Friedel Ziegelmayer
2016-09-13 13:23:11 +02:00
parent 73a5258876
commit 08c5df5e79
32 changed files with 2728 additions and 334 deletions

37
test/aes.spec.js Normal file
View File

@ -0,0 +1,37 @@
/* eslint max-nested-callbacks: ["error", 8] */
/* eslint-env mocha */
'use strict'
const expect = require('chai').expect
const crypto = require('../src')
const bytes = {
16: 'AES-128',
32: 'AES-256'
}
describe('AES-CTR', () => {
Object.keys(bytes).forEach((byte) => {
it(`${bytes[byte]} - encrypt and decrypt`, (done) => {
const key = new Buffer(parseInt(byte, 10))
key.fill(5)
const iv = new Buffer(16)
iv.fill(1)
crypto.aes.create(key, iv, (err, cipher) => {
expect(err).to.not.exist
cipher.encrypt(new Buffer('hello'), (err, res) => {
expect(err).to.not.exist
cipher.decrypt(res, (err, res) => {
expect(err).to.not.exist
expect(res).to.be.eql(new Buffer('hello'))
done()
})
})
})
})
})
})