-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathblowfish-ecb.js
executable file
·38 lines (30 loc) · 1.29 KB
/
blowfish-ecb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var mcrypt = require('..');
var assert = require('assert');
describe('MCrypt instance (BLOWFISH-ECB)', function() {
var mc = new mcrypt.MCrypt('blowfish', 'ecb');
it('should be an object', function() {
assert(typeof mc == 'object', 'there is an object');
});
describe('open', function() {
var key = 'YpQ3SXbNe9O/Vca/h+FVKQ==';
var plaintext = '1165096\0';
var ciphertext = 'LRo7D+VTxVw=';
it('should open without error', function() {
assert.doesNotThrow(function() {
mc.validateKeySize(false);
mc.open(new Buffer(key, 'base64'));
}, 'there is error when opened with key');
});
describe('encrypt', function() {
it('plaintext and decrypted ciphertext should be same', function(){
assert.equal(ciphertext, mc.encrypt(plaintext).toString('base64'), 'ciphertext are not same');
});
});
describe('decrypt', function() {
it('ciphertext and encrypted plaintext should be same', function(){
var result = mc.decrypt(new Buffer(ciphertext, 'base64')).toString();
assert.equal(plaintext, result, 'plaintext are not same');
});
});
});
});