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

Function testEncryption

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

Source from the content-addressed store, hash-verified

67}
68
69async function testEncryption(
70 {
71 ciphertext,
72 algorithm,
73 plaintext,
74 hash,
75 publicKeyBuffer,
76 privateKeyBuffer
77 },
78 modify = false) {
79 const {
80 publicKey,
81 privateKey
82 } = await importVectorKey(
83 publicKeyBuffer,
84 privateKeyBuffer,
85 algorithm.name,
86 hash,
87 ['encrypt'],
88 ['decrypt']);
89
90 if (modify)
91 plaintext = Buffer.from(plaintext); // make a copy
92
93 const encodedPlaintext = Buffer.from(plaintext).toString('hex');
94
95 const result = await subtle.encrypt(algorithm, publicKey, plaintext);
96 if (modify)
97 plaintext[0] = 255 - plaintext[0];
98
99 assert.strictEqual(
100 result.byteLength * 8,
101 privateKey.algorithm.modulusLength);
102
103 const out = await subtle.decrypt(algorithm, privateKey, result);
104
105 assert.strictEqual(
106 Buffer.from(out).toString('hex'),
107 encodedPlaintext);
108}
109
110async function testEncryptionLongPlaintext({ algorithm,
111 plaintext,

Calls 4

encryptMethod · 0.80
importVectorKeyFunction · 0.70
fromMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…