mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2024-12-18 02:20:40 +00:00
chore: cleanup crypto sign fucntion
This commit is contained in:
parent
043caedc94
commit
6921f8d503
@ -67,19 +67,16 @@ module.exports = class Crypto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static sign(key, msg, salt = crypto.randomBytes(32)) {
|
static sign(key, msg, salt = crypto.randomBytes(32)) {
|
||||||
// console.log(key.d());
|
|
||||||
const base = new BigNumber(emsaPSS(msg, salt));
|
const base = new BigNumber(emsaPSS(msg, salt));
|
||||||
const power = new BigNumber(key.d());
|
const power = new BigNumber(key.d());
|
||||||
const mod = new BigNumber(key.n());
|
const mod = new BigNumber(key.n());
|
||||||
|
const buffer = modPow(base, power, mod).toBEBuffer();
|
||||||
|
|
||||||
//Somehow sometimes we have a 514 byte hex key that starts with "00". In that case use only the last 512 bytes
|
if (buffer.byteLength !== 257 || buffer[0] === 0x00)
|
||||||
var hexString = modPow(base, power, mod).toBEBuffer().toString('hex');
|
return buffer.slice(1).toString('base64');
|
||||||
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"');
|
||||||
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\"");
|
return buffer.toString('base64');
|
||||||
hexString = hexString.substr(2);
|
|
||||||
}
|
|
||||||
return Buffer.from(hexString, 'hex').toString('base64');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static pad(d) {
|
static pad(d) {
|
||||||
|
Loading…
Reference in New Issue
Block a user