1、md5加密:md5.js
md5.js 共有6中加密方法:hex_md5(s), b64_md5(s), str_md5(s), hex_hmac_md5(key, data), b64_hmac_md5(key, data), str_hmac_md5(key, data)
<script src="js/md5.js"></script>
var pwd = hex_md5("val"); // val表示加密前的值
console.log(pwd); // pwd表示加密后的值
2、base64加密:base64.js
<script src="js/base64.js"></script>
var b = new Base64( );
var str = b.encode("admin:admin"); //加密
var str1 = b.decode(str); //解密
console.log(str);
console.log(str1)
3、sha1加密:sha1.js
<script src="js/sha1.js"></script>
var sha = hex_sha1('mima123465');
console.log(sha);
4、RSA加密:jsencrypt.js
<script src="js/jsencrypt.js"></script>
var str = "密码";
// 公钥 var publicKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoG"
// 私钥 var privateKey = "DANBgkqhkiG9w0BAQEFAASCAl"
加密
var encrypt = new JSEncrypt();
encrypt.setPublicKey(publicKey);
var encryptStr = encrypt.encrypt(str);
console.log("加密后:" + encryptStr);
解密
var decrypt = new JSEncrypt();
decrypt.setPrivateKey(privateKey);
var decryptStr = decrypt.decrypt(encryptStr);
console.log( "解密后:" + decryptStr);