I am wanting to sign a string with a private key using crypto.
The sign method returns an empty string, I was hoping to get a signiture.
var crypto = require('crypto');
var message = "This is a string I want to ensure is not tampered with.";
var diffieHellman = crypto.createDiffieHellman(1024);
var publicKey = diffieHellman.generateKeys("base64");
var privateKey = diffieHellman.getPrivateKey("base64");
var signer = crypto.createSign('RSA-SHA256');
signer.write(message, "ascii", function()
{
var signature = signer.sign(privateKey, 'base64');
console.log(publicKey);
console.log(privateKey);
console.log(signature);// Empty string ?
});
The public key and private key are generated fine.
Any help would be much appreciated.
This is a bug with crypto, confirmed here :
https://github.com/joyent/node/issues/6963
To solve, use a bit length of 512 and signer.
Here is working code