RSA加密算法原理:
https://blog.csdn.net/a745233700/article/details/102341542#:~:text=RSA加密算法是一,也都是公开的。
vue实现:npm install jsencrypt 下载插件
import { JSEncrypt } from 'jsencrypt'
// 加密公钥
const key = `----`
// 加密
export function setEncrypt (msg) {
const jsencrypt = new JSEncrypt()
jsencrypt.setPublicKey(key)
return jsencrypt.encrypt(msg)
}
// 解密私钥
const privateKey = `---`
// 解密
export function decrypt (msg) {
let decrypt = new JSEncrypt()
decrypt.setPrivateKey(privateKey)
var decryptMsg = decrypt.decrypt(msg)
return decryptMsg
}
后端
https://www.cnblogs.com/nihaorz/p/10690643.html
这是一个RSA加解密工具类RSAUtils.java,实现公钥加密私钥解密和私钥解密公钥解密
值得注意的是后端要获取到私钥,通过私钥进行解密,
可以在yaml中配置私钥,使用@ConfigurationProperties(prefix = "rsa")赋值给属性