var RSA = require('/wxapp_rsa.js')
// RSA加签
var sign_rsa = new RSA.RSAKey()
//privateKey_pkcs1需要是-----BEGIN PRIVATE KEY-----开头的私钥
sign_rsa = RSA.KEYUTIL.getKey(privateKey_pkcs1)
console.log('签名RSA:')
console.log(sign_rsa)
var hashAlg = 'MD5withRSA'
var hSig = sign_rsa.signString("12345678901234567890", hashAlg)
hSig = RSA.hex2b64(hSig)// hex 转 b64
console.log("签名结果:" + hSig)
// RSA 验签
var verify_rsa = new RSA.RSAKey()
verify_rsa = RSA.KEYUTIL.getKey(publicKey_pkcs1)
console.log('验签RSA:')
console.log(verify_rsa)
hSig = RSA.b64tohex(hSig)
var ver = verify_rsa.verifyString("12345678901234567890", hSig)
console.log('验签结果:' + ver)
// RSA加密 【加密字段长度不大于117】
var encrypt_rsa = new RSA.RSAKey()
encrypt_rsa = RSA.KEYUTIL.getKey(rsa_public_key)
console.log('加密RSA:')
console.log(encrypt_rsa)
var encStr = encrypt_rsa.encrypt('1234567890')
console.log(encStr)
encStr = RSA.hex2b64(encStr)
console.log("加密结果:" + encStr)
// RSA 解密
var decrypt_rsa = new RSA.RSAKey()
decrypt_rsa = RSA.KEYUTIL.getKey(rsa_public_key_private)
console.log('解密RSA:')
console.log(decrypt_rsa)
encStr = RSA.b64tohex(encStr)
var decStr = decrypt_rsa.decrypt(encStr)
console.log("解密结果:" + decStr)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)