Last updated
SHA-512 vs SHA-256 Comparison
Property SHA-256 SHA-512
----------- ------- -------
Output size 256 bits (64 hex) 512 bits (128 hex)
Block size 512 bits 1024 bits
Word size 32-bit 64-bit
Rounds 64 80
Speed (64-bit) Baseline Often faster than SHA-256
Security margin High Higher
Use case General purpose High-security, 64-bit servers
Output Format Options
- Lowercase hex (128 chars):
9b71d224bd62f3785d96d46ad3ea3d73... - Uppercase hex:
9B71D224BD62F3785D96D46AD3EA3D73... - Base64 (88 chars):
m3HSJL1i83hdltRq0+o9czGb+8KJDKra4t/3JRlnPKcjI8PZm6XBHXx6zG4UuQ== - Base64url (no padding):
m3HSJL1i83hdltRq0-o9czGb-8KJDKra4t_3JRlnPKcjI8PZm6XBHXx6zG4UuQ
When to Use SHA-512
- High-security applications requiring maximum hash strength
- Server-side applications on 64-bit hardware (often faster than SHA-256)
- Government and military document integrity verification
- JWT signing with HS512 for sensitive tokens
- HMAC-SHA512 for financial transaction authentication
- When compliance requirements specify SHA-512
Examples
Example 1: Basic Text Hashing
Input: hello
SHA-512: 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043
Input: Hello
SHA-512: 3615f80c9d293ed7402687f94b22d58e529b8cc7916f8fac7fddf7fbd5af4cf777d3d795a7a00a16bf7e7f3fb9561ee9baae480da9fe7a18769e71886b03f315
Input: "" (empty string)
SHA-512: cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
Example 2: File Integrity Verification
# Compute SHA-512 of a file (Linux/macOS)
sha512sum sensitive-document.pdf
# Output: 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca7... sensitive-document.pdf
# On macOS
shasum -a 512 sensitive-document.pdf
# On Windows (PowerShell)
Get-FileHash sensitive-document.pdf -Algorithm SHA512
# Verify against published hash
echo "9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca7 sensitive-document.pdf" | sha512sum --check
Example 3: HMAC-SHA512 for High-Security Authentication
Financial systems and government applications use HMAC-SHA512 for maximum security:
Key: high-security-secret-key
Message: {"transaction":"TXN-001","amount":50000,"currency":"USD"}
HMAC-SHA512 (hex): 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca7...
HMAC-SHA512 (base64): m3HSJL1i83hdltRq0+o9czGb+8KJDKra4t/3JRlnPKcjI8PZm6XBHXx6zG4UuQ==
Node.js implementation:
const crypto = require('crypto');
function signMessage(secret, message) {
return crypto
.createHmac('sha512', secret)
.update(message)
.digest('hex');
}
function verifyMessage(secret, message, signature) {
const expected = signMessage(secret, message);
return crypto.timingSafeEqual(
Buffer.from(expected, 'hex'),
Buffer.from(signature, 'hex')
);
}
Python implementation:
import hmac
import hashlib
import base64
def sign_message(secret: str, message: str) -> str:
return hmac.new(
secret.encode('utf-8'),
message.encode('utf-8'),
hashlib.sha512
).hexdigest()
def sign_message_base64(secret: str, message: str) -> str:
raw = hmac.new(
secret.encode('utf-8'),
message.encode('utf-8'),
hashlib.sha512
).digest()
return base64.b64encode(raw).decode()