* RSA 私钥签名加密 * @param {string} data - * @param {string} publicKeyBase - * @returns {string} -
(data, publicKeyBase = RSA_PRIVATE_KEY_PKCS8)
| 100 | * @returns {string} - |
| 101 | */ |
| 102 | function RSAencrypt(data, publicKeyBase = RSA_PRIVATE_KEY_PKCS8) { |
| 103 | const clearKey = publicKeyBase.replace(/\r/g, "") |
| 104 | const keyBytes = Buffer.from(clearKey, "base64") |
| 105 | const privateKey = crypto.createPrivateKey({ |
| 106 | key: keyBytes, |
| 107 | format: "der", |
| 108 | type: "pkcs8" |
| 109 | }) |
| 110 | const dest = crypto.privateEncrypt({ |
| 111 | key: privateKey, |
| 112 | padding: crypto.constants.RSA_PKCS1_PADDING, |
| 113 | }, data) |
| 114 | return dest.toString("base64") |
| 115 | } |
| 116 | |
| 117 | export { getStringMD5, AESdecrypt, AESencrypt, Base64decrypt, Base64encrypt, RSAencrypt } |