Cryto.js: Nasty workaround for incorrect signature (257 vs 256) and hex key length (514 vs 512)

For some unknown reason, the signature gets a length of 257 bytes instead of 256 bytes, and the length of the hex value is 514 bytes instead of 512 bytes.

This works around it, until a proper fix is implemented. The bug seems to be caused by https://github.com/node-ebics/node-ebics-client/blob/master/lib/crypto/Crypto.js#L71 somehow.

Signed-off-by: Herman van Hazendonk <github.com@herrie.org>
This commit is contained in:
Herrie 2021-03-17 11:13:39 +01:00 committed by Herman van Hazendonk
parent f027bc4048
commit 61581d1af7

View File

@ -72,8 +72,20 @@ module.exports = class Crypto {
const power = new BigNumber(key.d()); const power = new BigNumber(key.d());
const mod = new BigNumber(key.n()); const mod = new BigNumber(key.n());
//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);
var base64String = Buffer.from(hexString, 'hex').toString('base64')
return base64String;
}
else
{
return (modPow(base, power, mod)).toBEBuffer().toString('base64'); return (modPow(base, power, mod)).toBEBuffer().toString('base64');
} }
}
static pad(d) { static pad(d) {
const dLen = d.length; const dLen = d.length;