cryptojs包下载地址:https://github.com/brix/crypto-js/releases

百度地址:https://pan.baidu.com/s/1j7AL6IRUEj2mh_1vKrAl_w

一、导入包

前端aes加解密之cryptojs

<script src="js/crypto-js.js"></script>

二、进行加解密

    var myString = "hellow word";//要被加密的字符串
    var myKey= "dsf4d5s4f456";//秘钥

    //1.进行加密
    var encrypted = CryptoJS.AES.encrypt(myString, myKey);
    //输出加密后的字符串
    console.log(encrypted);

    //2.进行解密,输入要解密的密文和秘钥
    var decrypted = CryptoJS.AES.decrypt(encrypted, myKey);//默认是base64格式
    //输出解密后的字符串
    console.log(decrypted.toString(CryptoJS.enc.Utf8));//转化为utf8

 

在开发中注意保护好秘钥

 

相关文章: