sha1base64ase加密
Posted xieyongbin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sha1base64ase加密相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html>
<head>
<title>sha1、base64、ase加密</title>
<meta charset="utf-8" >
<meta name="renderer" content="webkit">
<meta name="author" content="XYB" />
<meta name="viewport" content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no">
<link rel="stylesheet" href="/common/css/init.css">
</head>
<body>
<div class="relative">
<input type="text" id="text"/>  
<input type="button" value="sha1加密" onclick="tunnel()"/>  
<input type="button" value="base64加密" onclick="basefunc()"/>  
<input type="button" value="ase加密" onclick="asefunc()"/>
</div>
</body>
<script src="/common/js/util/jquery-1.9.1.min.js"></script>
<script src="https://blog-static.cnblogs.com/files/xieyongbin/sha1.min.js"></script>
<script src="https://blog-static.cnblogs.com/files/xieyongbin/base64.min.js"></script>
<script src="https://blog-static.cnblogs.com/files/xieyongbin/ase.min.js"></script>
<script src="/common/js/init.js"></script>
<script>
/** 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);
}
</script>
</html>
以上是关于sha1base64ase加密的主要内容,如果未能解决你的问题,请参考以下文章