mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2024-12-25 22:01:48 +00:00
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:
parent
f027bc4048
commit
61581d1af7
@ -72,7 +72,19 @@ 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);
|
||||
var base64String = Buffer.from(hexString, 'hex').toString('base64')
|
||||
return base64String;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (modPow(base, power, mod)).toBEBuffer().toString('base64');
|
||||
}
|
||||
}
|
||||
|
||||
static pad(d) {
|
||||
|
Loading…
Reference in New Issue
Block a user