1.引用js
<script src="js/jsencrypt.min.js"></script>
2.加密
var PUBLIC_KEY = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCYwfy......';
var encrypt = new JSEncrypt();
encrypt.setPublicKey(PUBLIC_KEY);
var key = '123456';
var str = {name:'123456'};
var newVal = encrypt.encrypt(key);
console.log(newVal);// ghqdi9pCz9nNutO7LEbz7EIIZILrivB5I5OFIcqZYfQJrPDAnlzu......
var newStr = encrypt.encrypt(str);
console.log(newStr); // go6DyXxlCceh4cPVwbCn1HGYn5Vmzu...