-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
32 lines (30 loc) · 1.04 KB
/
index.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
<!DOCTYPE html>
<html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>SHA-512 哈希生成器</title>
</head>
<body>
<h1>SHA-512 哈希生成器</h1>
<br>
<label for="inputText">输入文本:</label>
<input type="text" id="inputText">
<br><br>
<button onclick="generateSHA512()">生成 SHA-512 哈希值</button>
<p id="hashResult"></p>
<script>
async function generateSHA512() {
const inputText = document.getElementById("inputText").value;
const encoder = new TextEncoder();
const data = encoder.encode(inputText);
const hashBuffer = await crypto.subtle.digest('SHA-512', data);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
document.getElementById("hashResult").innerHTML = "SHA-512 哈希值: " + hashHex;
}
</script>
<br>
<p>可以把源码下载到本地使用,更安全</p>
</body>
</html>