2014-10-07 14:32:23 -04:00
|
|
|
'use strict';
|
2014-06-05 09:26:19 -04:00
|
|
|
|
2014-11-21 09:06:29 -05:00
|
|
|
var Crypto = require('../../../src/js/crypto/crypto'),
|
|
|
|
config = require('../../../src/js/app-config').config,
|
2014-10-07 14:32:23 -04:00
|
|
|
util = require('crypto-lib').util;
|
2014-06-05 09:26:19 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('Crypto unit tests', function() {
|
|
|
|
this.timeout(20000);
|
2014-06-05 09:26:19 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
var crypto,
|
|
|
|
password = 'password',
|
|
|
|
keySize = config.symKeySize,
|
|
|
|
ivSize = config.symIvSize;
|
2014-06-05 09:26:19 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
crypto = new Crypto();
|
|
|
|
});
|
2014-06-05 09:26:19 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
afterEach(function() {});
|
2014-06-05 09:26:19 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('AES encrypt/decrypt', function() {
|
|
|
|
it('should work', function(done) {
|
|
|
|
var plaintext = 'Hello, World!';
|
|
|
|
var key = util.random(keySize);
|
|
|
|
var iv = util.random(ivSize);
|
2014-06-05 09:26:19 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
crypto.encrypt(plaintext, key, iv, function(err, ciphertext) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(ciphertext).to.exist;
|
2014-06-05 09:26:19 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
crypto.decrypt(ciphertext, key, iv, function(err, decrypted) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(decrypted).to.equal(plaintext);
|
2014-06-05 09:26:19 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
done();
|
2014-06-05 09:26:19 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2014-06-05 09:26:19 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe("PBKDF2 (Async/Worker)", function() {
|
|
|
|
it('should work', function(done) {
|
|
|
|
var salt = util.random(keySize);
|
2014-06-05 09:26:19 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
crypto.deriveKey(password, salt, keySize, function(err, key) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(util.base642Str(key).length * 8).to.equal(keySize);
|
2014-06-05 09:26:19 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
done();
|
2014-06-05 09:26:19 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
|
2014-06-05 09:26:19 -04:00
|
|
|
});
|