MCPcopy Index your code
hub / github.com/nodejs/node / testCipher3

Function testCipher3

test/parallel/test-crypto-cipheriv-decipheriv.js:64–85  ·  view source on GitHub ↗
(key, iv)

Source from the content-addressed store, hash-verified

62
63
64function testCipher3(key, iv) {
65 if (!crypto.getCiphers().includes('id-aes128-wrap')) {
66 common.printSkipMessage(`unsupported id-aes128-wrap test`);
67 return;
68 }
69 // Test encryption and decryption with explicit key and iv.
70 // AES Key Wrap test vector comes from RFC3394
71 const plaintext = Buffer.from('00112233445566778899AABBCCDDEEFF', 'hex');
72
73 const cipher = crypto.createCipheriv('id-aes128-wrap', key, iv);
74 let ciph = cipher.update(plaintext, 'utf8', 'buffer');
75 ciph = Buffer.concat([ciph, cipher.final('buffer')]);
76 const ciph2 = Buffer.from('1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE5',
77 'hex');
78 assert(ciph.equals(ciph2));
79 const decipher = crypto.createDecipheriv('id-aes128-wrap', key, iv);
80 let deciph = decipher.update(ciph, 'buffer');
81 deciph = Buffer.concat([deciph, decipher.final()]);
82
83 assert(deciph.equals(plaintext),
84 `encryption/decryption with key ${key} and iv ${iv}`);
85}
86
87{
88 const Cipheriv = crypto.Cipheriv;

Calls 7

includesMethod · 0.80
concatMethod · 0.80
updateMethod · 0.65
assertFunction · 0.50
fromMethod · 0.45
finalMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected