-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdes.html
35 lines (34 loc) · 1.27 KB
/
des.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DES 加解密</title>
</head>
<body>
<h1>DES 加解密</h1>
<label for="text">输入文本:</label>
<input type="text" id="text"><br><br>
<label for="key">密钥:</label>
<input type="text" id="key"><br><br>
<button onclick="desEncrypt()">加密</button>
<button onclick="desDecrypt()">解密</button>
<p id="result"></p>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js"></script>
<script src="crypto.js"></script>
<script>
function desEncrypt() {
const text = document.getElementById('text').value;
const key = document.getElementById('key').value;
const encrypted = CryptoJS.DES.encrypt(text, key);
document.getElementById('result').innerText = encrypted.toString();
}
function desDecrypt() {
const encrypted = document.getElementById('text').value;
const key = document.getElementById('key').value;
const bytes = CryptoJS.DES.decrypt(encrypted, key);
const decrypted = bytes.toString(CryptoJS.enc.Utf8);
document.getElementById('result').innerText = decrypted;
}
</script>
</body>
</html>