SHA-512哈希生成器
从任意文本生成SHA-512哈希值
输入文本
SHA-512哈希值
SHA-512哈希值将显示在此处…
什么是SHA-512哈希?
SHA-512是一种密码学哈希函数,由NIST在FIPS 180-4中定义,是SHA-2家族中最大的成员。它接受任意长度的输入,生成固定512位(64字节)的消息摘要,以128个十六进制字符的形式呈现。SHA-512广泛应用于数字签名(Ed25519内部使用SHA-512)、HMAC构造、文件完整性验证,以及需要较大安全余量的密码学协议。
SHA-512以1024位(128字节)为块进行处理,使用64位字运算和80轮压缩。其八个初始哈希值来源于前八个质数的平方根小数部分,80个轮常量来源于前80个质数的立方根小数部分。由于使用原生64位运算,即便产生更长的摘要,SHA-512在现代64位处理器上的速度通常也快于SHA-256。
SHA-384、SHA-512/224和SHA-512/256均为SHA-512的截断变体,共享相同的内部结构,但使用不同的初始哈希值并输出更少的位数。当需要SHA-2家族最大的摘要长度,或协议明确要求SHA-512(如Ed25519或某些基于HMAC的密钥派生方案)时,SHA-512是正确选择。它提供256位碰撞抵抗,与SHA-3-512相当,远超SHA-256的128位界限。
为什么使用在线SHA-512生成器?
计算SHA-512哈希通常需要终端命令或几行代码。这个基于浏览器的工具让你无需安装软件、切换终端或编写临时脚本,即可即时生成SHA-512摘要。
SHA-512哈希生成器使用场景
SHA-2家族变体对比
SHA-512属于FIPS 180-4定义的SHA-2家族。下表对比了与SHA-512共享64位内部架构的SHA-2变体,并以SHA-256作为参照。
| 变体 | 摘要长度 | 十六进制长度 | 字节大小 | 适用场景 |
|---|---|---|---|---|
| SHA-256 | 256 bits | 64 hex chars | 32 bytes | TLS certificates, blockchain, JWTs, SRI |
| SHA-384 | 384 bits | 96 hex chars | 48 bytes | TLS 1.3 CertificateVerify, CNSA/Suite B |
| SHA-512 | 512 bits | 128 hex chars | 64 bytes | Digital signatures, HMAC, Ed25519, file integrity |
| SHA-512/224 | 224 bits | 56 hex chars | 28 bytes | SHA-512 speed on 64-bit CPUs, 224-bit output |
| SHA-512/256 | 256 bits | 64 hex chars | 32 bytes | SHA-512 speed on 64-bit CPUs, 256-bit output |
SHA-512 与 SHA-256、SHA-384、SHA-3-512 对比
选择合适的哈希算法取决于你的安全需求、性能约束和协议规范。SHA-512在SHA-2家族中提供最宽的摘要,且在64位硬件上通常比SHA-256更快。以下对比涵盖了做出选择时最关键的属性。
| 属性 | SHA-512 | SHA-256 | SHA-384 | SHA-3-512 |
|---|---|---|---|---|
| Digest size | 512 bits (128 hex) | 256 bits (64 hex) | 384 bits (96 hex) | 512 bits (128 hex) |
| Block size | 1024 bits | 512 bits | 1024 bits | 1600 bits (sponge) |
| Word size | 64 bits | 32 bits | 64 bits | N/A (sponge) |
| Rounds | 80 | 64 | 80 | 24 |
| Collision resistance | 2^256 operations | 2^128 operations | 2^192 operations | 2^256 operations |
| Security status | Secure | Secure | Secure | Secure |
| Standard | FIPS 180-4 | FIPS 180-4 | FIPS 180-4 | FIPS 202 |
| Web Crypto API | Yes | Yes | Yes | No |
| 64-bit optimized | Yes | No (32-bit words) | Yes | Yes |
| Primary use today | Ed25519, HMAC, file checksums | TLS, blockchain, SRI | TLS 1.3, CNSA | Backup standard |
SHA-512的内部工作原理
SHA-512通过Merkle–Damgård构造处理输入,使用1024位块。它初始化八个64位状态字(H0–H7),来源于前八个质数的平方根小数部分。每个块经过80轮混合运算,这些运算对64位字使用按位操作(AND、XOR、NOT、右旋转、右移位),并结合来自前80个质数立方根的80个轮常量。
SHA-512: 309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f
989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f
(512 bits = 64 bytes = 128 hex characters)
| 步骤 | 描述 |
|---|---|
| Padding | Append a 1-bit, then zeros until the message length is 896 mod 1024. Append the original length as a 128-bit big-endian integer. |
| Block splitting | Divide the padded message into 1024-bit (128-byte) blocks. |
| Message schedule | Expand each 16-word (64-bit) block into 80 words using sigma functions with right-rotate and right-shift operations on 64-bit values. |
| Compression | Process 80 rounds per block using Ch, Maj, and two Sigma functions with 80 round constants derived from the cube roots of the first 80 primes. |
| Output | Concatenate the eight 64-bit state words (H0–H7) into a 512-bit (64-byte) digest, rendered as 128 hexadecimal characters. |
更宽的64位字大小是与SHA-256的关键区别。在64位CPU上,每次操作处理的位数是SHA-256的两倍,这正是为什么SHA-512在基准测试中经常优于SHA-256,尽管其运行80轮而非64轮。雪崩效应确保翻转单个输入位会改变512个输出位中约50%的位。
SHA-512代码示例
SHA-512在每种主流语言和运行时中均原生支持。Web Crypto API无需任何库即可在浏览器中提供该功能。以下示例涵盖了常见模式,包括Unicode处理和文件哈希。
// Works in all modern browsers and Node.js 18+
async function sha512(text) {
const data = new TextEncoder().encode(text)
const hashBuffer = await crypto.subtle.digest('SHA-512', data)
const hashArray = Array.from(new Uint8Array(hashBuffer))
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('')
}
await sha512('hello world')
// → "309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f"
// Node.js (built-in crypto module)
const crypto = require('crypto')
crypto.createHash('sha512').update('hello world').digest('hex')
// → "309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f"import hashlib
# Basic SHA-512 hash
result = hashlib.sha512(b'hello world').hexdigest()
print(result)
# → "309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee..."
# Hash a string with Unicode (encode to bytes first)
text = 'café ☕'
hashlib.sha512(text.encode('utf-8')).hexdigest()
# → 128-character hex string
# Hash a large file in chunks (memory-efficient)
with open('release.tar.gz', 'rb') as f:
sha = hashlib.sha512()
for chunk in iter(lambda: f.read(8192), b''):
sha.update(chunk)
print(sha.hexdigest())package main
import (
"crypto/sha512"
"fmt"
)
func main() {
data := []byte("hello world")
hash := sha512.Sum512(data)
fmt.Printf("%x\n", hash)
// → 309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f...
}# Using sha512sum (Linux) or shasum (macOS) echo -n "hello world" | sha512sum # → 309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee... - # macOS echo -n "hello world" | shasum -a 512 # → 309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee... - # Verify a file checksum echo "309ecc48... myfile.bin" | sha512sum -c # → myfile.bin: OK # Using openssl (cross-platform) echo -n "hello world" | openssl dgst -sha512 # → SHA2-512(stdin)= 309ecc489c12d6eb4cc40f50c902f2b4...