cryptos
来源:互联网 发布:finereport 数据库 编辑:程序博客网 时间:2024/05/16 05:04
<html><head> <title></title> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=0"> <script src="https://cdn.bootcss.com/crypto-js/3.1.2/rollups/aes.js"></script> <script src="https://cdn.bootcss.com/crypto-js/3.1.2/rollups/tripledes.js"></script> <script src="https://cdn.bootcss.com/crypto-js/3.1.2/components/enc-base64-min.js"></script></head><body><script> { //3DES : CBC iv must be 8 bytes,key 24 bytes var t_key = CryptoJS.enc.Utf8.parse("123456781234567812345678"); var t_text = "helloworld大家好很高兴见到各位"; var t_i = CryptoJS.enc.Utf8.parse("1234abcd"); var t_encrypted = CryptoJS.TripleDES.encrypt(t_text, t_key, {iv: t_i}); var plain = CryptoJS.TripleDES.decrypt(t_encrypted, t_key, {iv: t_i}); var plainString = CryptoJS.enc.Utf8.stringify(plain); alert(t_text == plainString); //cipher : nJY8TIeIxUm8X8hgAk4MVh5G38/cN+c7ZO2i93/ZcK3o8krzVOMiC6xUD9wBwd60 //AES : CBC iv must be 16 bytes,key 16 bytes var a_key = CryptoJS.enc.Utf8.parse("1234567812345678"); var a_text = "helloworld大家好很高兴见到各位"; var a_i = CryptoJS.enc.Utf8.parse("1234abcd1234abcd"); var a_encrypted = CryptoJS.AES.encrypt(a_text, a_key, {iv: a_i}); var plain2 = CryptoJS.AES.decrypt(a_encrypted, a_key, {iv: a_i}); var plainString2 = CryptoJS.enc.Utf8.stringify(plain2); alert(a_text == plainString2); //cipher : Pt8dNEKCP9O5yrO59CvzvjpQW/c61osQSWr2hC+uGXW5HrDEtFV5JIpcZ6ixbQ1Y }</script></body></html>
0 0