bitcore/test/aescbc.js

74 lines
2.2 KiB
JavaScript
Raw Normal View History

2014-08-27 17:15:10 -07:00
var should = require('chai').should();
var AESCBC = require('../lib/expmt/aescbc');
2014-08-27 17:15:10 -07:00
describe('AESCBC', function() {
2014-08-27 17:15:10 -07:00
describe('@encrypt', function() {
it('should return encrypt one block', function() {
var password = "password";
var messagebuf = new Buffer(128 / 8 - 1);
messagebuf.fill(0);
var encbuf = AESCBC.encrypt(messagebuf, password);
2014-08-27 17:15:10 -07:00
encbuf.length.should.equal(128 / 8 + 128 / 8);
});
});
describe('@decrypt', function() {
it('should decrypt that which was encrypted', function() {
var password = "password";
var messagebuf = new Buffer(128 / 8 - 1);
messagebuf.fill(0);
var encbuf = AESCBC.encrypt(messagebuf, password);
var messagebuf2 = AESCBC.decrypt(encbuf, password);
2014-08-27 17:15:10 -07:00
messagebuf2.toString('hex').should.equal(messagebuf.toString('hex'));
});
});
describe('@encryptCipherkey', function() {
it('should return encrypt one block', function() {
var cipherkeybuf = new Buffer(256 / 8);
cipherkeybuf.fill(0x10);
var ivbuf = new Buffer(128 / 8);
ivbuf.fill(0);
var messagebuf = new Buffer(128 / 8 - 1);
messagebuf.fill(0);
var encbuf = AESCBC.encryptCipherkey(messagebuf, cipherkeybuf, ivbuf);
2014-08-27 17:15:10 -07:00
encbuf.length.should.equal(128 / 8 + 128 / 8);
});
it('should return encrypt two blocks', function() {
var cipherkeybuf = new Buffer(256 / 8);
cipherkeybuf.fill(0x10);
var ivbuf = new Buffer(128 / 8);
ivbuf.fill(0);
var messagebuf = new Buffer(128 / 8);
messagebuf.fill(0);
var encbuf = AESCBC.encryptCipherkey(messagebuf, cipherkeybuf, ivbuf);
2014-08-27 17:15:10 -07:00
encbuf.length.should.equal(128 / 8 + 128 / 8 + 128 / 8);
});
});
describe('@decryptCipherkey', function() {
it('should decrypt that which was encrypted', function() {
var cipherkeybuf = new Buffer(256 / 8);
cipherkeybuf.fill(0x10);
var ivbuf = new Buffer(128 / 8);
ivbuf.fill(0);
var messagebuf = new Buffer(128 / 8);
messagebuf.fill(0);
var encbuf = AESCBC.encryptCipherkey(messagebuf, cipherkeybuf, ivbuf);
var messagebuf2 = AESCBC.decryptCipherkey(encbuf, cipherkeybuf);
2014-08-27 17:15:10 -07:00
messagebuf2.toString('hex').should.equal(messagebuf.toString('hex'));
});
});
});