"Keypair" is a more explanatory name, and also should be less confused with other kinds of keys (particularly "cipher keys", which are the keys used in symmetric block ciphers, especially AES).
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
var ECIES = require('../lib/expmt/ecies');
|
|
var should = require('chai').should();
|
|
var Keypair = require('../lib/keypair');
|
|
var Hash = require('../lib/hash');
|
|
|
|
describe('#ECIES', function() {
|
|
|
|
it('should make a new ECIES object', function() {
|
|
var ecies = new ECIES();
|
|
should.exist(ecies);
|
|
});
|
|
|
|
it('should make a new ECIES object when called without "new"', function() {
|
|
var ecies = ECIES();
|
|
should.exist(ecies);
|
|
});
|
|
|
|
var fromkey = Keypair().fromRandom();
|
|
var tokey = Keypair().fromRandom();
|
|
var messagebuf = Hash.sha256(new Buffer('my message is the hash of this string'));
|
|
|
|
describe('@encrypt', function() {
|
|
|
|
it('should return a buffer', function() {
|
|
var encbuf = ECIES.encrypt(messagebuf, tokey, fromkey);
|
|
Buffer.isBuffer(encbuf).should.equal(true);
|
|
});
|
|
|
|
});
|
|
|
|
describe('@decrypt', function() {
|
|
|
|
it('should decrypt that which was encrypted', function() {
|
|
var encbuf = ECIES.encrypt(messagebuf, tokey, fromkey);
|
|
var messagebuf2 = ECIES.decrypt(encbuf, tokey);
|
|
messagebuf2.toString('hex').should.equal(messagebuf.toString('hex'));
|
|
});
|
|
|
|
});
|
|
|
|
});
|