-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdes.html
44 lines (42 loc) · 1.92 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
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>DES加密及Hex和MD5值示例</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js"></script>
</head>
<body>
<label for="input-text">输入字符串:</label>
<input type="text" id="input-text" placeholder="输入要加密的字符串">
<button onclick="encryptText()">加密</button></br>
<label for="output-text">加密后的字符串 (Hex编码):</label>
<input type="text" id="output-text" placeholder="Hex编码结果将显示在这里" readonly></br>
<label for="md5-text">MD5值 (Hex编码):</label>
<input type="text" id="md5-text" placeholder="MD5值将显示在这里" readonly>
<button onclick="copy()">复制</button></br>
<script>
function encryptText() {
var inputText = document.getElementById('input-text').value;
var key = CryptoJS.enc.Utf8.parse('iamfrost'); // DES密钥
var iv = CryptoJS.enc.Utf8.parse('199902066'); // DES初始向量
var encrypted = CryptoJS.DES.encrypt(inputText, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
var hex = encrypted.ciphertext.toString(CryptoJS.enc.Hex); // Hex编码值
var md5 = CryptoJS.MD5(hex).toString(CryptoJS.enc.Hex); // MD5值 (Hex编码)
document.getElementById('output-text').value = hex;
document.getElementById('md5-text').value = md5.toUpperCase ();
}
function copy(){
var md5Value = document.getElementById('md5-text').value;
navigator.clipboard.writeText(md5Value).then(function() {
alert('MD5值已复制到剪贴板');
}, function(err) {
alert('复制失败: ', err);
});
}
</script>
</body>
</html>