Merge pull request #50 from Herrie82/master

Cryto.js: Nasty workaround for incorrect signature (257 vs 256) and h…
This commit is contained in:
Dimitar Nanov 2021-03-30 08:58:35 +03:00 committed by GitHub
commit 043caedc94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -72,7 +72,14 @@ module.exports = class Crypto {
const power = new BigNumber(key.d());
const mod = new BigNumber(key.n());
return (modPow(base, power, mod)).toBEBuffer().toString('base64');
//Somehow sometimes we have a 514 byte hex key that starts with "00". In that case use only the last 512 bytes
var hexString = modPow(base, power, mod).toBEBuffer().toString('hex');
if(hexString.substr(0,2) === "00" && hexString.length == 514)
{
console.log("hex string of key starts with \"00\" and is 514 bytes long, fixing it to be 512 bytes long by stripping leading \"00\"");
hexString = hexString.substr(2);
}
return Buffer.from(hexString, 'hex').toString('base64');
}
static pad(d) {