Skip to content

correction on Crypto Sign class example (Using Sign and Verify objects as streams) https://nodejs.org/api/crypto.html#crypto_class_sign #31307

Closed
@Shubhamachval

Description

@Shubhamachval

// 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions