/** sha1 **/
function tunnel(){
alert(Sha1Min($("#text").val()));
}
/** base64 **/
function basefunc(){
var password = $("#text").val();
var base = new Base64();
var encypass = base.encode(password);
var decryptpass = base.decode(encypass);
console.log("加密之前的密码是:"+password);
console.log("加密之后的结果是:"+encypass);
console.log("解密之前的结果是:"+encypass);
console.log("解密之后的结果是:"+decryptpass);
}
/** ase **/
function asefunc(){
var key = CryptoJS.enc.Utf8.parse("8NONwyJtHesysWpM");
var plaintText = 'ABCDEFGH'; // 明文
var encryptedData = CryptoJS.AES.encrypt(plaintText, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
console.log("加密前:"+plaintText);
console.log("加密后:"+encryptedData);
encryptedData = encryptedData.ciphertext.toString();
var encryptedHexStr = CryptoJS.enc.Hex.parse(encryptedData);
var encryptedBase64Str = CryptoJS.enc.Base64.stringify(encryptedHexStr);
var decryptedData = CryptoJS.AES.decrypt(encryptedBase64Str, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
var decryptedStr = decryptedData.toString(CryptoJS.enc.Utf8);
console.log("解密后:"+decryptedStr);
var pwd = "PCsUFtgog9/qpqmqXsuCRQ==";
//加密服务端返回的数据
var decryptedData = CryptoJS.AES.decrypt(pwd, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
console.log("解密服务端返回的数据:"+decryptedStr);
}
标签:sha1,console,log,base64,mode,ase,var,ensp,CryptoJS
来源: https://www.cnblogs.com/xieyongbin/p/10929832.html