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

Function testCipher1

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

Source from the content-addressed store, hash-verified

9const isFipsEnabled = crypto.getFips();
10
11function testCipher1(key, iv) {
12 // Test encryption and decryption with explicit key and iv
13 const plaintext =
14 '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
15 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
16 'jAfaFg**';
17 const cipher = crypto.createCipheriv('des-ede3-cbc', key, iv);
18 let ciph = cipher.update(plaintext, 'utf8', 'hex');
19 ciph += cipher.final('hex');
20
21 const decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv);
22 let txt = decipher.update(ciph, 'hex', 'utf8');
23 txt += decipher.final('utf8');
24
25 assert.strictEqual(txt, plaintext,
26 `encryption/decryption with key ${key} and iv ${iv}`);
27
28 // Streaming cipher interface
29 // NB: In real life, it's not guaranteed that you can get all of it
30 // in a single read() like this. But in this case, we know it's
31 // quite small, so there's no harm.
32 const cStream = crypto.createCipheriv('des-ede3-cbc', key, iv);
33 cStream.end(plaintext);
34 ciph = cStream.read(cStream.readableLength);
35
36 const dStream = crypto.createDecipheriv('des-ede3-cbc', key, iv);
37 dStream.end(ciph);
38 txt = dStream.read(dStream.readableLength).toString('utf8');
39
40 assert.strictEqual(txt, plaintext,
41 `streaming cipher with key ${key} and iv ${iv}`);
42}
43
44
45function testCipher2(key, iv) {

Calls 5

updateMethod · 0.65
finalMethod · 0.45
endMethod · 0.45
readMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…