由于前后端使用的RSA加密规范不统一,加密方式又再次进行更改,使用微信小程序wx_rsa加密方式,主要是由于jsencrypt自身使用的是pkcs1加密规范,但后端使用的是pkcs8加密规范。哎。。。苦逼!
使用
(1)引用文件
const RSA = require(’./wx_rsa.js’)
wx_rsa可从官网下载,地址:https://github.com/UFO0001/WX_RSA
(2)可以直接在界面中引用,但我选择在utils再创建一个文件rsa.js
const RSA = require('./wx_rsa.js')
export function RSAEncrypt (word, publicKey) {
let PublicKey = '-----BEGIN PUBLIC KEY-----' + publicKey + '-----END PUBLIC KEY-----'
let encrypt_rsa = new RSA.RSAKey()
encrypt_rsa = RSA.KEYUTIL.getKey(PublicKey)
let encStr = encrypt_rsa.encrypt(word)
encStr = RSA.hex2b64(encStr)
return encStr
}
export function RSADecrypt (word, privateKey) {
let PrivateKey = '-----BEGIN PUBLIC KEY-----' + privateKey + '-----END PUBLIC K