npm install --save jsencrypt
import {JSEncrypt} from 'jsencrypt';
//导入公钥
if ( publicKey.indexOf('-----') < 0 ) {
publicKey = "-----BEGIN PUBLIC KEY-----" + publicKey + "-----END PUBLIC KEY-----";
}
var encrypt = new JSEncrypt();
encrypt.setPublicKey(publicKey);
if( password instanceof Array ){
password = password.join('|');
}
data = encrypt.encrypt(password)
或者
data = encodeURIComponent( encrypt.encrypt(password) )
引入cryptico.js
shaKey和pubKey为后台返回
res = res || {
"shaKey": "",
"pubKey": ""
};
cryptico.setPublicKeyString(res);
加密密码
cryptico.encrypt(pwd);