Site updated: 2024-01-06 23:59:19
This commit is contained in:
1 parent
919548836d
commit
d3fe637d72
205 files changed
+346
-203
No files matched your search
Vendored
+1
@@ -0,0 +1 @@
|
||||
!function(t,e){"object"==typeof exports?module.exports=exports=e():"function"==typeof define&&define.amd?define([],e):t.CryptoJS=e()}(this,function(){var l,r,t,e,i,f,n,o,s,a,c,h,u,d,p,_,v,y,g,B,w,k,S,m,x,b,H,z,A,C,D,R,E,M,F,P,W,O,U,I,K,X,L,j,N,T,Z,q,G,J,$,Q,V,Y,tt,et,rt,it,nt,ot,st,at,ct,ht,lt,ft,ut,dt,pt,_t,vt,yt,gt,Bt,wt,kt,St,mt,xt,bt,Ht,zt,At,Ct,Dt,Rt,Et,Mt,Ft,Pt=Pt||(l=Math,r=Object.create||function(t){var e;return Wt.prototype=t,e=new Wt,Wt.prototype=null,e},e=(t={}).lib={},i=e.Base={extend:function(t){var e=r(this);return t&&e.mixIn(t),e.hasOwnProperty("init")&&this.init!==e.init||(e.init=function(){e.$super.init.apply(this,arguments)}),(e.init.prototype=e).$super=this,e},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.init.prototype.extend(this)}},f=e.WordArray=i.extend({init:function(t,e){t=this.words=t||[],this.sigBytes=null!=e?e:4*t.length},toString:function(t){return(t||o).stringify(this)},concat:function(t){var e=this.words,r=t.words,i=this.sigBytes,n=t.sigBytes;if(this.clamp(),i%4)for(var o=0;o<n;o++){var s=r[o>>>2]>>>24-o%4*8&255;e[i+o>>>2]|=s<<24-(i+o)%4*8}else for(o=0;o<n;o+=4)e[i+o>>>2]=r[o>>>2];return this.sigBytes+=n,this},clamp:function(){var t=this.words,e=this.sigBytes;t[e>>>2]&=4294967295<<32-e%4*8,t.length=l.ceil(e/4)},clone:function(){var t=i.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){function e(e){e=e;var r=987654321,i=4294967295;return function(){var t=((r=36969*(65535&r)+(r>>16)&i)<<16)+(e=18e3*(65535&e)+(e>>16)&i)&i;return t/=4294967296,(t+=.5)*(.5<l.random()?1:-1)}}for(var r,i=[],n=0;n<t;n+=4){var o=e(4294967296*(r||l.random()));r=987654071*o(),i.push(4294967296*o()|0)}return new f.init(i,t)}}),n=t.enc={},o=n.Hex={stringify:function(t){for(var e=t.words,r=t.sigBytes,i=[],n=0;n<r;n++){var o=e[n>>>2]>>>24-n%4*8&255;i.push((o>>>4).toString(16)),i.push((15&o).toString(16))}return i.join("")},parse:function(t){for(var e=t.length,r=[],i=0;i<e;i+=2)r[i>>>3]|=parseInt(t.substr(i,2),16)<<24-i%8*4;return new f.init(r,e/2)}},s=n.Latin1={stringify:function(t){for(var e=t.words,r=t.sigBytes,i=[],n=0;n<r;n++){var o=e[n>>>2]>>>24-n%4*8&255;i.push(String.fromCharCode(o))}return i.join("")},parse:function(t){for(var e=t.length,r=[],i=0;i<e;i++)r[i>>>2]|=(255&t.charCodeAt(i))<<24-i%4*8;return new f.init(r,e)}},a=n.Utf8={stringify:function(t){try{return decodeURIComponent(escape(s.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return s.parse(unescape(encodeURIComponent(t)))}},c=e.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new f.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=a.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(t){var e=this._data,r=e.words,i=e.sigBytes,n=this.blockSize,o=i/(4*n),s=(o=t?l.ceil(o):l.max((0|o)-this._minBufferSize,0))*n,a=l.min(4*s,i);if(s){for(var c=0;c<s;c+=n)this._doProcessBlock(r,c);var h=r.splice(0,s);e.sigBytes-=a}return new f.init(h,a)},clone:function(){var t=i.clone.call(this);return t._data=this._data.clone(),t},_minBufferSize:0}),e.Hasher=c.extend({cfg:i.extend(),init:function(t){this.cfg=this.cfg.extend(t),this.reset()},reset:function(){c.reset.call(this),this._doReset()},update:function(t){return this._append(t),this._process(),this},finalize:function(t){return t&&this._append(t),this._doFinalize()},blockSize:16,_createHelper:function(r){return function(t,e){return new r.init(e).finalize(t)}},_createHmacHelper:function(r){return function(t,e){return new h.HMAC.init(r,e).finalize(t)}}}),h=t.algo={},t);function Wt(){}function Ot(t,e,r){return t^e^r}function Ut(t,e,r){return t&e|~t&r}function It(t,e,r){return(t|~e)^r}function Kt(t,e,r){return t&r|e&~r}function Xt(t,e,r){return t^(e|~r)}function Lt(t,e){return t<<e|t>>>32-e}function jt(t,e,r,i){var n=this._iv;if(n){var o=n.slice(0);this._iv=void 0}else o=this._prevBlock;i.encryptBlock(o,0);for(var s=0;s<r;s++)t[e+s]^=o[s]}function Nt(t){if(255==(t>>24&255)){var e=t>>16&255,r=t>>8&255,i=255&t;255===e?(e=0,255===r?(r=0,255===i?i=0:++i):++r):++e,t=0,t+=e<<16,t+=r<<8,t+=i}else t+=1<<24;return t}function Tt(){for(var t=this._X,e=this._C,r=0;r<8;r++)mt[r]=e[r];e[0]=e[0]+1295307597+this._b|0,e[1]=e[1]+3545052371+(e[0]>>>0<mt[0]>>>0?1:0)|0,e[2]=e[2]+886263092+(e[1]>>>0<mt[1]>>>0?1:0)|0,e[3]=e[3]+1295307597+(e[2]>>>0<mt[2]>>>0?1:0)|0,e[4]=e[4]+3545052371+(e[3]>>>0<mt[3]>>>0?1:0)|0,e[5]=e[5]+886263092+(e[4]>>>0<mt[4]>>>0?1:0)|0,e[6]=e[6]+1295307597+(e[5]>>>0<mt[5]>>>0?1:0)|0,e[7]=e[7]+3545052371+(e[6]>>>0<mt[6]>>>0?1:0)|0,this._b=e[7]>>>0<mt[7]>>>0?1:0;for(r=0;r<8;r++){var i=t[r]+e[r],n=65535&i,o=i>>>16,s=((n*n>>>17)+n*o>>>15)+o*o,a=((4294901760&i)*i|0)+((65535&i)*i|0);xt[r]=s^a}t[0]=xt[0]+(xt[7]<<16|xt[7]>>>16)+(xt[6]<<16|xt[6]>>>16)|0,t[1]=xt[1]+(xt[0]<<8|xt[0]>>>24)+xt[7]|0,t[2]=xt[2]+(Line truncated
|
||||
@@ -0,0 +1,141 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>AES Encryption</title>
|
||||
<style>
|
||||
input[type="text"] {
|
||||
width: 100%;
|
||||
height: 30px;
|
||||
margin-top: 0px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
input {
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
<script src="./crypto-js.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
信息:<input type="text" id="content" /><br>
|
||||
秘钥:<input type="text" id="encryptionKey" /><br>
|
||||
是否使用IV向量:<input type="radio" id="useIv" value=0 checked onclick="selectUseIv(this.value)" />否 
|
||||
<input type="radio" id="useIv" value=1 onclick="selectUseIv(this.value)" />是<br>
|
||||
IV向量:<input type="text" id="iv" /><br>
|
||||
NoPadding:<input type="radio" id="useNoPadding" value=0 checked onclick="selectUseNoPadding(this.value)" />否 
|
||||
<input type="radio" id="useNoPadding" value=1 onclick="selectUseNoPadding(this.value)" />是<br>
|
||||
加密结果:<input type="text" id="value1" /><br>
|
||||
解密结果:<input type="text" id="value2" /><br>
|
||||
<input type="button" value="提交" onclick="submit()" />
|
||||
|
||||
<script>
|
||||
// 默认信息
|
||||
document.getElementById("content").value = '{"endTime": "", "keyword": "", "magnitude": "", "pageNum": 1, "pageSize": 10, "startTime": "", "xzqh": "420"}';
|
||||
// 默认aes秘钥
|
||||
document.getElementById("encryptionKey").value = "l5gzm2n78wriiqux";
|
||||
|
||||
// 加密函数
|
||||
function encryptAES(text, key, conf) {
|
||||
// 使用 CryptoJS.AES 对象进行加密
|
||||
var encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(text), CryptoJS.enc.Utf8.parse(key), conf);
|
||||
return encrypted.toString();
|
||||
}
|
||||
|
||||
// 解密函数
|
||||
function decryptAES(encryptedText, key, conf) {
|
||||
// 使用 CryptoJS.AES 对象进行解密
|
||||
var decrypted = CryptoJS.AES.decrypt(encryptedText, CryptoJS.enc.Utf8.parse(key), conf);
|
||||
return decrypted.toString(CryptoJS.enc.Utf8);
|
||||
}
|
||||
|
||||
// 提交
|
||||
function submit() {
|
||||
var encryptionKey = document.getElementById("encryptionKey").value;
|
||||
// 模式ECB、CBC
|
||||
// 补码Pkcs7、NoPadding
|
||||
var conf = {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
}
|
||||
// 是否使用NoPadding
|
||||
var useNoPadding = false;
|
||||
if (document.querySelector('input[id="useNoPadding"]:checked').value == 1) {
|
||||
useNoPadding = true;
|
||||
}
|
||||
// 判断是否使用iv向量
|
||||
if (document.querySelector('input[id="useIv"]:checked').value == 1) {
|
||||
conf.mode = CryptoJS.mode.CBC;
|
||||
if (useNoPadding) {
|
||||
conf.padding = CryptoJS.pad.NoPadding;
|
||||
}
|
||||
var iv = document.getElementById("iv").value;
|
||||
if (!iv) {
|
||||
selectUseIv(1);
|
||||
iv = document.getElementById("iv").value;
|
||||
}
|
||||
if (iv.length != 16) {
|
||||
alert("iv的长度必须是16位");
|
||||
return;
|
||||
}
|
||||
conf.iv = CryptoJS.enc.Utf8.parse(document.getElementById("iv").value);
|
||||
}
|
||||
// 加密
|
||||
var text = document.getElementById("content").value;
|
||||
if (useNoPadding) {
|
||||
const blockSize = 16; // AES块大小为16字节
|
||||
text = padToBlockSize(text, blockSize);
|
||||
}
|
||||
if (!text) {
|
||||
alert("信息不能为空");
|
||||
return;
|
||||
}
|
||||
document.getElementById("value1").value = encryptAES(text, encryptionKey, conf);
|
||||
// 解密
|
||||
var decryptText = decryptAES(document.getElementById("value1").value, encryptionKey, conf);
|
||||
if (useNoPadding) {
|
||||
decryptText = removePadding(decryptText);
|
||||
}
|
||||
document.getElementById("value2").value = decryptText;
|
||||
}
|
||||
|
||||
// 选择是否使用iv向量
|
||||
function selectUseIv(value) {
|
||||
if (value == 1) {
|
||||
document.querySelector('input[id="useIv"][value="0"]').checked = false;
|
||||
if (!document.getElementById("iv").value) {
|
||||
var randomBytes = CryptoJS.lib.WordArray.random(128 / 8);
|
||||
var randomHexString = randomBytes.toString(CryptoJS.enc.Hex);
|
||||
document.getElementById("iv").value = randomHexString.substring(0, 16);
|
||||
}
|
||||
} else {
|
||||
document.querySelector('input[id="useIv"][value="1"]').checked = false;
|
||||
document.getElementById("iv").value = "";
|
||||
}
|
||||
}
|
||||
|
||||
// 选择是否使用NoPadding
|
||||
function selectUseNoPadding(value) {
|
||||
if (value == 1) {
|
||||
document.querySelector('input[id="useNoPadding"][value="0"]').checked = false;
|
||||
} else {
|
||||
document.querySelector('input[id="useNoPadding"][value="1"]').checked = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 确保明文长度是块大小的整数倍
|
||||
function padToBlockSize(data, blockSize) {
|
||||
const paddingLength = blockSize - (data.length % blockSize);
|
||||
const padding = String.fromCharCode(paddingLength).repeat(paddingLength);
|
||||
return data + padding;
|
||||
}
|
||||
|
||||
// 去除填充
|
||||
function removePadding(plaintext) {
|
||||
const paddingLength = plaintext.charCodeAt(plaintext.length - 1);
|
||||
return plaintext.slice(0, -paddingLength);
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
<a href="/tools/aes/" style="font-size:16px;color:#72cecf">AES加解密</a>
|
||||
Reference in new issue
Block a user