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

Function testDecryption

test/parallel/test-webcrypto-encrypt-decrypt-rsa.js:32–67  ·  view source on GitHub ↗
({ ciphertext,
                                algorithm,
                                plaintext,
                                hash,
                                publicKeyBuffer,
                                privateKeyBuffer })

Source from the content-addressed store, hash-verified

30}
31
32async function testDecryption({ ciphertext,
33 algorithm,
34 plaintext,
35 hash,
36 publicKeyBuffer,
37 privateKeyBuffer }) {
38 if (ciphertext === undefined)
39 return;
40
41 const {
42 privateKey
43 } = await importVectorKey(
44 publicKeyBuffer,
45 privateKeyBuffer,
46 algorithm.name,
47 hash,
48 ['encrypt'],
49 ['decrypt']);
50
51 const encodedPlaintext = Buffer.from(plaintext).toString('hex');
52 const result = await subtle.decrypt(algorithm, privateKey, ciphertext);
53
54 assert.strictEqual(
55 Buffer.from(result).toString('hex'),
56 encodedPlaintext);
57
58 const ciphercopy = Buffer.from(ciphertext);
59
60 // Modifying the ciphercopy after calling decrypt should just work
61 const result2 = await subtle.decrypt(algorithm, privateKey, ciphercopy);
62 ciphercopy[0] = 255 - ciphercopy[0];
63
64 assert.strictEqual(
65 Buffer.from(result2).toString('hex'),
66 encodedPlaintext);
67}
68
69async function testEncryption(
70 {

Calls 3

importVectorKeyFunction · 0.70
toStringMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…