登录时对密码进行加密传输:
1.调接口,后端返回公钥
2.实例化对象
3.设置公钥
4.返回加密的字符串
encryptDate = (publicKey, data) => { // publicKey: 后端返回的公钥 data:要加密的字符串
if (publicKey) {
const encrypt = new JSEncrypt() // 1.实例化对象
encrypt.setPublicKey(publicKey) // 2. 设置公钥
return encrypt.encrypt(data) // 3. 返回加密的字符串
} else {
return ''
}
}
有用就顺手点个赞 啦啦啦啦啦(体力-1)