base64 加密是属于双向加密,就是加密后可以解密回来
MD5 是单向加密,就是加密后无法解密。
MD5 加盐加密就是将(用户名+密码)进行MD5加密(类似都叫加盐,这里用户名就是盐值)
支付宝的公钥私钥加密,公钥解密私钥,这个是最安全的加密方式.
另外https是使用了安全证书。
encryptlong是基于jsencrypt扩展的长文本分段加解密功能
引入jsencrypt实现数据RSA加密
import JSEncrypt from “jsencrypt” // 处理长文本数据报错 Message too long for RSA
引入encryptlong实现数据RSA加密
import encrypt from “encryptlong”
export default{
generateRsaKey(data){
//let data = "deviceId=20636&token=f6d20a8866c04a2d8ca50d5494242bad&salt=162366271653";
//初始化RSAKey
var rsa = new Jsrsasign.RSAKey();
//私钥要写开头和结束
var pk = '-----BEGIN PRIVATE KEY-----' + privateKey + '-----END PRIVATE KEY-----'
// 读取解析pem格式的秘钥, 生成秘钥实例 (RSAKey)
rsa = Jsrsasign.KEYUTIL.getKey(pk);
//sign
//加签,创建Signature对象,设置签名编码算法
var signature = new Jsrsasign.KJUR.crypto.Signature({"alg":"SHA1withRSA"})
//初始化
signature.init(rsa)
//传入待签明文
signature.updateString(data)
//签名, 得到16进制字符串结果
console.log("生成密钥(16进制字符串) "+ signature.sign())
//
//var encryptData = Jsrsasign.KJUR.crypto.Cipher.encrypt(signature.sign(), rsa);
//console.log("解密 "+ encryptData)
//生成base64密文
var sign = Jsrsasign.hextob64(signature.sign())
//console.log("SIGN Length: " + sign.length + ", Base64密文: " + sign)
return sign
//简化方式2: 方式1的基础上, 去掉显示读取私钥, 去掉初始化步骤(init(..))
var signature2 = new Jsrsasign.KJUR.crypto.Signature({"alg":"SHA1withRSA", "prvkeypem": prik})
signature2.updateString(data)
console.log("生成签名2(16进制字符串) "+ signature2.sign())
//参考
//对加密后的内容进行URI编码,将所有中文encoder掉(此函数是js原生函数)
//sign = encodeURIComponent(sign)
//console.log("SIGN URI编码: " + sign)
return sign
拼接到请求参数
//var params = data + '&sign=' + sign;
// console.log("接口 DATA params: " + params)
// return params
},
}
rsaPublicEncrypt(){
//注:处理长文本数据报错 Message too long for RSA
//let data = "deviceId=20636&token=f6d20a8866c04a2d8ca50d5494242bad&salt=162366271653";
let data = "password=123456";
//加密, 读取解析pem格式的秘钥, 生成秘钥实例 (RSAKey)
var rsa = new Jsrsasign.RSAKey();
console.log(rsa)
rsa = Jsrsasign.KEYUTIL.getKey('-----BEGIN PUBLIC KEY-----' + publicKey + '-----END PUBLIC KEY-----');
console.log("-----RSAKey-----")
console.log(rsa)
var encryptData = Jsrsasign.KJUR.crypto.Cipher.encrypt(data, rsa);
console.log("生成加密数据: " + encryptData)
}
/* JSEncrypt加密*/
rsaPublicData(data){
//公钥key
let jsencrypt = new JSEncrypt()
jsencrypt.setPublicKey(publicKey)
let result = jsencrypt.encrypt(JSON.stringify(data));
console.log("公钥加密:" + result)
return result
},
/* JSEncrypt解密*/
rsaPrivateData(data){
let jsencrypt = new JSEncrypt()
jsencrypt.setPrivateKey(privateKey)
let result = jsencrypt.decrypt(JSON.stringify(data));
console.log("私钥解密:" + result)
return result
},
encryptLong(data){
let encryptor = new EncryptLong()
encryptor.setPublicKey(publicKey)
/* 加密前必须把数据转化成字符串*/
let result = encryptor.encryptLong(JSON.stringify(data))
console.log("EncryptLong 公钥加密:" + result)
return result
},
decryptLong(data){
//私钥key
let encryptor = new EncryptLong()
encryptor.setPrivateKey(privateKey)
let result = encryptor.decryptLong(data)
console.log("DecryptLong 私钥解密:" + result)
return result
}
RSA公钥私钥加密解密
https://www.bejson.com/enc/rsa/#18
jsrsasign 进行 RSA 加密、解密、签名、验签
https://www.cnblogs.com/kgdxpr/p/12651650.html
在VUE中使用RSA加密解密加签解签
https://blog.csdn.net/weixin_34256074/article/details/91373035
https://blog.csdn.net/sophie_u/article/details/79881872
https://blog.csdn.net/shizhesx/article/details/109642336
后台
AES加密解密(key是16位)
https://www.cnblogs.com/ymxl/p/13322418.html
JAVA 中解密RSA算法JS加密实例详解
https://www.jb51.net/article/111141.htm