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

Function testSignVerify

test/common/crypto.js:61–81  ·  view source on GitHub ↗
(publicKey, privateKey)

Source from the content-addressed store, hash-verified

59
60// Tests that a key pair can be used for signing / verification.
61function testSignVerify(publicKey, privateKey) {
62 const message = Buffer.from('Hello Node.js world!');
63
64 function oldSign(algo, data, key) {
65 return createSign(algo).update(data).sign(key);
66 }
67
68 function oldVerify(algo, data, key, signature) {
69 return createVerify(algo).update(data).verify(key, signature);
70 }
71
72 for (const signFn of [sign, oldSign]) {
73 const signature = signFn('SHA256', message, privateKey);
74 for (const verifyFn of [verify, oldVerify]) {
75 for (const key of [publicKey, privateKey]) {
76 const okay = verifyFn('SHA256', message, key, signature);
77 assert(okay);
78 }
79 }
80 }
81}
82
83// Constructs a regular expression for a PEM-encoded key with the given label.
84function getRegExpForPEM(label, cipher) {

Calls 2

assertFunction · 0.50
fromMethod · 0.45

Tested by

no test coverage detected