-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathlib.serializablecipher.test.js
52 lines (47 loc) · 1.75 KB
/
lib.serializablecipher.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import C from '../src/index';
let data = {};
beforeAll(async () => {
data.message = new C.lib.WordArray([0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f]);
data.key = new C.lib.WordArray([0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f]);
data.iv = new C.lib.WordArray([0x20212223, 0x24252627, 0x28292a2b, 0x2c2d2e2f]);
await C.AES.loadWasm();
});
describe('lib-serializablecipher-test', () => {
test('testEncrypt', () => {
// Compute expected
let aes = C.algo.AES.createEncryptor(data.key, {
iv: data.iv
});
let ciphertext = aes.finalize(data.message);
let expected = new C.lib.CipherParams({
ciphertext: ciphertext,
key: data.key,
iv: data.iv,
algorithm: C.algo.AES,
mode: aes.cfg.mode,
padding: aes.cfg.padding,
blockSize: aes.blockSize,
formatter: C.format.OpenSSL
});
let actual = C.lib.SerializableCipher.encrypt(C.algo.AES, data.message, data.key, {
iv: data.iv
});
expect(actual.toString()).toBe(expected.toString());
expect(actual.ciphertext.toString()).toBe(expected.ciphertext.toString());
expect(actual.key.toString()).toBe(expected.key.toString());
expect(actual.iv.toString()).toBe(expected.iv.toString());
expect(actual.algorithm).toBe(expected.algorithm);
expect(actual.mode).toBe(expected.mode);
expect(actual.padding).toBe(expected.padding);
expect(actual.blockSize).toBe(expected.blockSize);
});
test('testDecrypt', () => {
let encrypted = C.lib.SerializableCipher.encrypt(C.algo.AES, data.message, data.key, {
iv: data.iv
}) + '';
let decrypted = C.lib.SerializableCipher.decrypt(C.algo.AES, encrypted, data.key, {
iv: data.iv
});
expect(decrypted.toString()).toBe(data.message.toString());
});
});