-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
35 lines (32 loc) · 1.32 KB
/
test.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
'use strict';
const crypto = require('crypto');
const assert = require('assert');
const ecies = require('./main.js');
describe('basic test', function () {
it('decryption result should be same as original text', function () {
// option parameter is optional, all options are optional except iv,
// when symmetric cipher is not in ecb mode, iv option must be offered.
// default option
const options = {
hashName: 'sha256',
hashLength: 32,
macName: 'sha256',
macLength: 32,
curveName: 'secp256k1',
symmetricCypherName: 'aes-128-ecb',
iv: null,
// iv is used in symmetric cipher, set null if you want to use cipher
// in ecb mode. set undefined if you want to use deprecated
// createCipheriv / createDecipher / EVP_BytesToKey
keyFormat: 'uncompressed',
s1: null, // optional shared information1
s2: null // optional shared information2
}
const ecdh = crypto.createECDH(options.curveName);
ecdh.generateKeys();
const plainText = Buffer.from ? Buffer.from('hello world') : new Buffer('hello world');
const encryptedText = ecies.encrypt(ecdh.getPublicKey(), plainText, options);
const decryptedText = ecies.decrypt(ecdh, encryptedText, options);
assert(plainText.toString('hex') == decryptedText.toString('hex'));
});
});