Open
Description
Version
v22.0.0
Platform
Darwin air.lan 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:19:05 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8112 arm64
Subsystem
crypto
What steps will reproduce the bug?
When using crypto.createSign to sign SM2, I got an incorrect signature. The same issue occurs with crypto.createVerify.
const crypto = require('crypto');
const data = "AABB";
var keys = {
privateKey: crypto.createPrivateKey(`-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBG0wawIBAQQgbjCNHopgvyGVfLaP
PamI9E9lf6jXT+xm1Pns1t/xQTihRANCAATV+I7HUGF2gC+miVl3JfjpoZaU2hrZ
QqHwKUNtIDE/uxxWNLBbYKaiLOWrbYA8skrWQWl3RkbXW4ZI28afRw9g
-----END PRIVATE KEY-----
`),
publicKey: crypto.createPublicKey(`-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE1fiOx1BhdoAvpolZdyX46aGWlNoa
2UKh8ClDbSAxP7scVjSwW2Cmoizlq22APLJK1kFpd0ZG11uGSNvGn0cPYA==
-----END PUBLIC KEY-----`)
};
var sig = crypto.createSign('sm3').update(data).sign(keys.privateKey);
// var sig = crypto.sign('sm3', data, keys.privateKey);
var ok = crypto.verify('sm3', data, keys.publicKey, sig);
console.log("verify: ", ok);
How often does it reproduce? Is there a required condition?
always.
What is the expected behavior? Why is that the expected behavior?
verify: true
What do you see instead?
verify: false
Additional information
No response
Activity