前端对密码加密
密码传给后台之前使用 jsencrypt 进行加密
import JSEncrypt from 'jsencrypt/bin/jsencrypt'
// 密钥对生成 http://web.chacuo.net/netrsakeypair
const publicKey = 'xxxx'
const privateKey = 'xxxx'
// 加密
export function encrypt(txt) {
const encryptor = new JSEncrypt()
encryptor.setPublicKey(publicKey) // 设置公钥
return encryptor.encrypt(txt) // 对需要加密的数据进行加密
}
// 解密
export function decrypt(txt) {
const encryptor = new JSEncrypt()
encryptor.setPrivateKey(privateKey)
return encryptor.decrypt(txt)
}
后台解密
对前台传来的密码解密
// 这里的密钥需要与前端的相同
String privateKey="xxx";
// 这里使用的 hutool工具包
RSA rsa=new RSA(privateKey,null);
String password = new String(rsa.decrypt("password==", KeyType.PrivateKey));
System.out.println(password);
版权声明:本文为qq_43338182原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。