rsa签名与验签
后台生成的公钥和私钥或者网上下载小工具自己生成
var pubkey = `-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoa2op/Fov4fBHj/02+sb
JHfpY62FZQe+xUrPCU87vibEVaUjn0DgcSwDesY9hV7dcVXyyIzFf3WcWp644sJX
1jHeUp7aRveZZCgt8aaURjPkeVnPYXyO3BwRUa8op25ibEtsgm3b/SLlFFRDKeo1
l3KKjCXagilSxi6ZPXpF3XuHqw+S2fRz7pDPzZTd+zFhd4hN7iiiETL1ZVMKW4jA
sKLDXd6biQBfol+EiXZ/cClEzC2W14EmmDdC6sYsWG6Kgi/vSNAJd4uS70wlpXCM
ZHLj0pUEKRBSnxHwEJe3V7OXh/vLJ2pNBYYKli/FizwuvCX/2pqyNZc8uyyX6pGT
pQIDAQAB
-----END PUBLIC KEY-----`
var privateKey = `-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQChrain8Wi/h8Ee
P/Tb6xskd+ljrYVlB77FSs8JTzu+JsRVpSOfQOBxLAN6xj2FXt1xVfLIjMV/dZxa
nrjiwlfWMd5SntpG95lkKC3xppRGM+R5Wc9hfI7cHBFRryinbmJsS2yCbdv9IuUU
VEMp6jWXcoqMJdqCKVLGLpk9ekXde4erD5LZ9HPukM/NlN37MWF3iE3uKKIRMvVl
UwpbiMCwosNd3puJAF+iX4SJdn9wKUTMLZbXgSaYN0LqxixYboqCL+9I0Al3i5Lv
TCWlcIxkcuPSlQQpEFKfEfAQl7dXs5eH+8snak0FhgqWL8WLPC68Jf/amrI1lzy7
LJfqkZOlAgMBAAECggEAAKBprOz0mPlvuCxLSKbqngOQ9f/wKmoTRTR7BPA3rQ79
Z8+SCcX4mLew88Lc7i1l8lCA9mIFSe8swfUnhkl2ia/7ypovAmNnRsoZE3yvym3d
DtNYSGpxK004i/Z/09ZLr1vDeeXvGlYOSTviXsE3n/Sjs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1Vdl3iIsA==
-----END PRIVATE KEY-----`
// 创建Signature对象,设置签名编码算法
let sig = new KJUR.crypto.Signature({
"alg": "SHA1withRSA",
"prvkeypem": privateKey,
});
// 添加原文
sig.updateString('需要签名的字符串');
// 进行签名
sign = hextob64(sig.sign());
console.log(sign)
// 创建Signature对象,设置签名编码算法
let sig1 = new KJUR.crypto.Signature({"alg": "SHA1withRSA","prvkeypem": pubkey,});
// 添加原文
sig1.updateString("签名的原字符串");
// 验证签名
let isValid = sig1.verify(b64tohex(sign));
// 控制台打印
console.log(isValid);
后台为.NET,SHA1的算法验证通过其他暂未试验