<script type="text/javascript">
/**
* AES加密
* @param {string} s_text 等待加密的字符串
* @param {string} s_key 16位密钥
* @param {array} ctx 可选,默认为 { mode: CryptoJS.mode.ECB,padding: CryptoJS.pad.ZeroPadding }
* @return {string}
*/
function aes_encrypt (s_text, s_key, ctx) {
if (ctx == undefined) ctx = { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.ZeroPadding }
var key = CryptoJS.enc.Utf8.parse(s_key);
var encrypt_data = CryptoJS.AES.encrypt(s_text, key, ctx);
return encrypt_data.toString();
}
/**
* AES解密
* @param {string} s_text 等待解密的密文
* @param {string} s_key 16位密钥
* @param {array} ctx 可选,默认为 { mode: CryptoJS.mode.ECB,padding: CryptoJS.pad.ZeroPadding }
* @return {string}
*/
function aes_decrypt (s_text, s_key, ctx) {
if (ctx == undefined) ctx = { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.ZeroPadding }
var key = CryptoJS.enc.Utf8.parse(s_key);
var decrypt_data = CryptoJS.AES.decrypt(s_text, key, ctx);
return decrypt_data.toString(CryptoJS.enc.Utf8);
}
</script>