Nodejs Crypto Sign / Verify :: Error: PEM routines: PEM_read_bio: no start line

I am trying to use nodejs crypto lib to sign / verify lines of information with the following code:

// Generated by CoffeeScript 1.8.0
(function() {
  var crypto, tPriv, tPub1, tPub2, tSig, __Key, __Sign, __Verify;

  crypto = require('crypto');

  __Sign = function(aObj, aPrivKey) {
    var tRet, tSign;
    tSign = crypto.createSign('RSA-SHA256');
    tSign.update(aObj);
    tRet = tSign.sign(aPrivKey, 'base64');
    console.log(tRet);
    return tRet;
  };

  __Verify = function(aObj, aPubKey) {
    var tRet, tVerify;
    tVerify = crypto.createVerify('RSA-SHA256');
    tRet = tVerify.verify(aObj, aPubKey, 'base64');
    console.log(tRet);
    return tRet;
  };

  __Key = crypto.getDiffieHellman('modp5');
  __Key.generateKeys();
  tPub1 = __Key.getPublicKey('base64');
  tPub2 = __Key.getPublicKey('base64');
  tPriv = __Key.getPrivateKey('base64');
  tSig = __Sign(tPub1, tPriv);
  console.log(__Verify(tSig, tPub2));
}).call(this);

      

however, when run it gives the following error:

# 140735266407184:error:0906D06C:PEM routines:PEM_read_bio:no start line:../deps/openssl/openssl/crypto/pem/pem_lib.c:703:Expecting: ANY PRIVATE KEY# 
# 
# crypto.js:398
#   var ret = this._binding.sign(toBuf(key));
#                           ^
# Error: SignFinal error
#     at Sign.sign (crypto.js:398:27)
#     at __Sign (~/testSig.js:11:18)
#     at Object.<anonymous> (~/testSig.js:34:10)
#     at Object.<anonymous> (~/testSig.js:38:4)
#     at Module._compile (module.js:456:26)
#     at Object.Module._extensions..js (module.js:474:10)
#     at Module.load (module.js:356:32)
#     at Function.Module._load (module.js:312:12)
#     at Function.Module.runMain (module.js:497:10)
#     at startup (node.js:119:16)

      

I've read the docs @ http://nodejs.org/api/crypto.html#crypto_crypto_createsign_algorithm but I honestly don't even know where to start this error. I think he is complaining about the private key, but the private key I provide is from his own library.

If someone can point me in the right direction, I would appreciate it.

+3


source to share





All Articles