mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-06-23 05:41:52 +00:00
feat: use webcrypto in favor of node-forge
BREAKING CHANGE: generateKeyPair is now async
This commit is contained in:
37
test/aes.spec.js
Normal file
37
test/aes.spec.js
Normal 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()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user