You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
correction on Crypto Sign class example (Using Sign and Verify objects as streams) https://nodejs.org/api/crypto.html#crypto_class_sign #31307
// According to website (https://nodejs.org/api/crypto.html#crypto_class_sign) In following code //console.log() print false which is a wrong output.
//but it should print true when sign.write() and verify.write() have same data as input
const sign = crypto.createSign('SHA256');
sign.write('some data to sign');
sign.end();
const signature = sign.sign(privateKey, 'hex');
const verify = crypto.createVerify('SHA256');
verify.write('some data to sign');
verify.end();
console.log(verify.verify(publicKey, signature));
// Prints: true or false
//solution
//please update verify.verify(publicKey,signature) to verify.verify(publicKey,signature,'hex')
//or
//update sign.sign(privateKey, 'hex') to sign.sign(privateKey)
// then above code print right output on specified inputs.
// According to website (https://nodejs.org/api/crypto.html#crypto_class_sign) In following code //console.log() print false which is a wrong output.
//but it should print true when sign.write() and verify.write() have same data as input
const crypto = require('crypto');
const { privateKey, publicKey } = crypto.generateKeyPairSync('ec', {
namedCurve: 'sect239k1'
});
const sign = crypto.createSign('SHA256');
sign.write('some data to sign');
sign.end();
const signature = sign.sign(privateKey, 'hex');
const verify = crypto.createVerify('SHA256');
verify.write('some data to sign');
verify.end();
console.log(verify.verify(publicKey, signature));
// Prints: true or false
//solution
//please update verify.verify(publicKey,signature) to verify.verify(publicKey,signature,'hex')
//or
//update sign.sign(privateKey, 'hex') to sign.sign(privateKey)
// then above code print right output on specified inputs.
Activity
himself65 commentedon Jan 11, 2020
tniessen commentedon Jan 19, 2020
I think this was fixed by #31313.