rawGenerateEncryptData(rsa, obj, function sign(hmac) {
let rsa = new JSEncrypt()
rsa.setPrivateKey(privateKey)
return rsa.sign(hmac, CryptoJS.SHA256, "sha256");
})
Where the error occurred
RSAKey.prototype.sign = function (text, digestMethod, digestName) {
// ....
var h = c.toString(16);
if ((h.length & 1) == 0) {
return h;
}
else {
return "0" + h;
}
}
The cause of the problem:
The digestName is SHA-256, but the length of h may not be 512. If you use the operator &, it will not append 0 to the start of the string when the length is 510, but SHA-256 requires 256. Additionally, 510 >> 1 is 255.
My Code
Where the error occurred
The cause of the problem: The digestName is SHA-256, but the length of h may not be 512. If you use the operator &, it will not append 0 to the start of the string when the length is 510, but SHA-256 requires 256. Additionally, 510 >> 1 is 255.
Fix it