如何在nodeJS中签名缓冲区

时间:2018-12-03 08:38:44

标签: javascript node.js signature

我正在尝试使用此代码在NodeJS中签名缓冲区

var crypto = require('crypto');

var privateKey = "-----BEGIN PRIVATE KEY-----\n"+
  Buffer.from("dm7NmAXbOZQ3RX//RPdrjuJgyqfqUFUA2qMt461BjTc=", 'base64')+
  "\n-----END PRIVATE KEY-----";

var sign = crypto.createSign('RSA-SHA256');
sign.update(Buffer.from("P101RhuYuayFsAsa633mBzGPGn761sXjXiEPFV8sCY=", 'base64'));
var signature = sign.sign(privateKey, 'binary');
console.log(signature);

但是它给了我这个错误

internal/crypto/sig.js:83
  var ret = this._handle.sign(key, passphrase, rsaPadding, pssSaltLength);
                         ^
Error: error:0906D064:PEM routines:PEM_read_bio:bad base64 decode

我该如何解决?

0 个答案:

没有答案