如何生成私钥和公钥,使用私钥对任意文本的哈希进行签名,然后在其他地方使用公钥来验证签名?
答案 0 :(得分:1)
使用URSA(OpenSSL加密的Node.js包装器):
var ursa = require('ursa');
// Generate RSA private key (public key included)
var keyPair = ursa.generatePrivateKey();
// Convert public key to string
var pub = keyPair.toPublicPem('base64');
// Create buffer from text
var data = new Buffer('Hello, world!');
// Create MD5 hash and sign with private key
var sig = keyPair.hashAndSign('md5', data);
// Elsewhere...
// Create public key object from PEM string
pub = ursa.createPublicKey(pub, 'base64');
// Verify signature - should return true
pub.hashAndVerify('md5', data, sig);