码迷,mamicode.com
首页 > 其他好文 > 详细

sha1、base64、ase加密

时间:2019-05-27 11:50:47      阅读:343      评论:0      收藏:0      [点我收藏+]

标签:user   NPU   href   ati   ring   name   ext   mini   cal   

<!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"/>&ensp;&ensp;
<input type="button" value="sha1加密" onclick="tunnel()"/>&ensp;&ensp;
<input type="button" value="base64加密" onclick="basefunc()"/>&ensp;&ensp;
<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>

sha1、base64、ase加密

标签:user   NPU   href   ati   ring   name   ext   mini   cal   

原文地址:https://www.cnblogs.com/xieyongbin/p/10929832.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!