Encoding and Hashing
Executive Summary
Encoding transforms data into another representation. Hashing produces a fixed-length fingerprint of data. Encryption protects data with a key.
This cheatsheet is for quick lookup when handling files, payloads, hashes, certificates, tokens, and encoded strings.
Encoding vs Hashing vs Encryption
| Concept | Reversible | Key Required | Common Use |
|---|---|---|---|
| Encoding | Yes | No | Data formatting and transport |
| Hashing | No | No | Integrity checks and password storage |
| Encryption | Yes | Yes | Confidentiality |
Base64
Encode a file:
Encode without line wrapping:
Decode:
Encode a string:
Decode a string:
PowerShell encode:
PowerShell decode:
Hex
String to hex:
Hex to string:
Hex dump a file:
URL Encoding
URL encode with Python:
URL decode with Python:
Common characters:
| Character | Encoded |
|---|---|
| Space | %20 |
" |
%22 |
# |
%23 |
% |
%25 |
& |
%26 |
' |
%27 |
/ |
%2F |
: |
%3A |
= |
%3D |
? |
%3F |
@ |
%40 |
Hashing Files
MD5:
SHA1:
SHA256:
SHA512:
PowerShell hash:
Hashing Strings
MD5:
SHA256:
Python SHA256:
Identify Hash Lengths
| Hash | Hex Length |
|---|---|
| MD5 | 32 |
| SHA1 | 40 |
| SHA256 | 64 |
| SHA512 | 128 |
| NTLM | 32 |
| bcrypt | Variable, often starts with $2a$, $2b$, or $2y$ |
| SHA-crypt | Starts with $5$ or $6$ |
Common Password Hash Indicators
| Format | Meaning |
|---|---|
$1$ |
MD5-crypt |
$2a$, $2b$, $2y$ |
bcrypt |
$5$ |
SHA256-crypt |
$6$ |
SHA512-crypt |
$krb5asrep$ |
Kerberos AS-REP hash |
$krb5tgs$ |
Kerberos TGS hash |
aad3b435b51404eeaad3b435b51404ee |
Empty LM hash |
| 32 hex chars | Could be MD5 or NTLM |
OpenSSL Encryption
Encrypt file:
Decrypt file:
Generate random bytes:
Generate random base64:
Certificates
View certificate details:
Check remote TLS certificate:
Show certificate dates:
Show certificate subject:
JWT Quick Checks
JWTs usually have three dot-separated parts:
Decode JWT header:
Decode JWT payload:
If padding is missing, add = characters until decoding works.
File Integrity Workflow
| Step | Command |
|---|---|
| Hash original | sha256sum file.bin |
| Transfer file | Use chosen transfer method |
| Hash received copy | sha256sum file.bin |
| Compare hashes | Hashes should match exactly |
Notes
- Base64 is not encryption.
- Hashes are not reversible.
- Fast hashes like MD5 and SHA1 are weak for password storage.
- Use SHA256 or stronger for integrity checks.
- Use authenticated encryption or trusted secure transfer methods for sensitive data.