Join our Newsletter — 33% off our NHI Course
Home› Guides› Encoding, Encryption and Hashing: Telling Them Apart With…
Guide Data Security

Encoding, Encryption and Hashing: Telling Them Apart With Security Examples

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 27 November 2026 12 min read
On this page

A password stored as Base64 in a config file is not protected, yet code reviews and incident reports keep finding exactly that, because encoding, encryption and hashing are still confused. Encoding changes the representation of data so another system can carry it, encryption hides data from anyone without the key, and hashing produces a fixed fingerprint that cannot be turned back into the input. This guide explains what each one does, compares them side by side, walks through real misuse patterns (encoded secrets, fast password hashes, unkeyed integrity checks) and gives a simple way to choose. It is for developers, DevOps engineers and junior security staff. Data masking and tokenisation are covered separately in Encryption vs Hashing vs Masking.

Key takeaways

  • Encoding is not security. RFC 4648 states that base encoding does not provide any computational confidentiality; anyone can decode Base64, hex or URL encoding without a secret.
  • Encryption needs a key, and the key is the whole problem. AES protects data only as long as the key is kept separate from the ciphertext and managed properly.
  • Hashing is one way, but not all hashes suit passwords. Fast hashes such as SHA-256 are right for integrity checks and wrong for passwords; use Argon2id, scrypt, bcrypt or PBKDF2.
  • A plain hash does not prove who sent a message. Anyone can recompute it. Use an HMAC or a digital signature when you need integrity against an attacker.
  • Pick by the question you are answering. Need to transport it: encode. Need it back, secretly: encrypt. Need to check it without storing it: hash. Need to detect tampering: HMAC or sign.

What each one does

Encoding

Encoding maps data from one representation to another using a public, fixed scheme. No key is involved, and the transformation is fully reversible by anyone who knows (or guesses) the scheme. Its purpose is compatibility: carrying binary data through systems that expect text, or making characters safe for a URL, HTML page or JSON document.

  • Base64 and Base64url: defined in RFC 4648 (October 2006, Proposed Standard), alongside Base32, Base32hex and Base16 (hex). Base64url swaps characters so output is safe in URLs and file names. The trailing = padding is a common giveaway.
  • Percent (URL) encoding, HTML entities, Unicode escapes: make characters safe for a specific context. Output encoding for HTML and JavaScript is a security control against injection, but it protects the page, not the data. See the Input Validation and Output Encoding Guide.
  • Character encodings (UTF-8): map characters to bytes. Not a protection of any kind.

Encryption

Encryption transforms plaintext into ciphertext using an algorithm and a secret key, so that only holders of the right key can reverse it. The algorithm is public; the security rests on the key.

  • Symmetric: the same key encrypts and decrypts. NIST FIPS 197 specifies AES with 128 bit blocks and key lengths of 128, 192 or 256 bits. Use it in an authenticated mode such as GCM so that tampering is detected. See the Authenticated Encryption and Block Cipher Modes Guide.
  • Asymmetric: a public key encrypts (or verifies), a private key decrypts (or signs). Used for key exchange and signatures, as in TLS.

Hashing

A cryptographic hash function maps input of any length to a fixed length digest. NIST FIPS 180-4 (Secure Hash Standard) specifies the SHA-2 family and describes the purpose plainly: digests let you detect whether a message has changed since the digest was made. A good hash is one way (you cannot recover the input) and collision resistant (you cannot find two inputs with the same digest). There is no key and nothing to decrypt.

  • Fast general purpose hashes (SHA-256, SHA-512, SHA-3): file integrity, content addressing, digital signature input.
  • Password hashing functions (Argon2id, scrypt, bcrypt, PBKDF2): deliberately slow, salted and, for Argon2id and scrypt, memory hard, so that guessing is expensive. See the Password Hashing and Key Derivation Guide.
  • Keyed hashes (HMAC): RFC 2104 defines HMAC, which combines a hash function with a shared secret key so a receiver who holds the key can verify the message was not altered and came from another key holder.

Side-by-side comparison

PropertyEncodingEncryptionHashingHMAC
ReversibleYes, by anyoneYes, with the keyNoNo
Secret neededNoneKey (symmetric) or private keyNone (passwords add a per-user salt, optionally a pepper)Shared secret key
PurposeCompatibility and transportConfidentiality (and integrity in AEAD modes)Integrity check, fingerprinting, password verificationIntegrity and authenticity between key holders
Output lengthGrows with input (Base64 adds about a third)About the input size plus nonce and tagFixed (SHA-256: 256 bits)Fixed (hash length)
Typical examplesBase64, hex, URL encodingAES-GCM, ChaCha20-Poly1305, RSA-OAEPSHA-256, SHA-3; Argon2id, bcrypt for passwordsHMAC-SHA256
Protects againstNothing (it is not a security control)Disclosure to anyone without the keyAccidental change; with slow hashes, password cracking at scaleDeliberate tampering by anyone without the key
Fails whenTreated as protectionKey stored with data, weak mode, no integrityFast hash used for passwords, used to "authenticate" dataKey leaked, non constant-time comparison

Quick recognition: a string of letters, digits, + and / ending in = is probably Base64; 64 hex characters is probably a SHA-256 digest; a value starting $argon2id$ or $2b$ is a password hash with its parameters embedded. None of these patterns tells you whether the value is safe to expose; the type of protection does.

Security examples of misuse

Encoded secrets in configuration

MITRE classifies this as CWE-261 Weak Encoding for Password. Its examples show a database password read from a properties file and a network credential read from the registry, each Base64 decoded before use; anyone who can open the file or key can recover the password. RFC 4648's security considerations note that people have exposed passwords this way, believing the encoding protected them.

Kubernetes is the most common modern case. Secret values in manifests are Base64 encoded, not encrypted, and encryption at rest in etcd has to be configured. In research published in November 2023, Aqua Security found registry credentials in Kubernetes Secret manifests committed to public GitHub repositories, including an SAP artifact repository credential, described as a single Base64 decode away from plaintext. See the exposed Kubernetes Secrets incident and How to check Kubernetes secrets encryption at rest.

  • Attacker view: credentials in files map to ATT&CK T1552.001 Credentials In Files. Decoding Base64 adds seconds, not protection.
  • Scanner blind spot: secret scanners that look only for plaintext patterns may miss encoded values. Check that your scanner decodes Base64 before matching. See the Git Secret Scanning Guide.

Treating a JWT payload as private

A signed JSON Web Token has three Base64url encoded parts. The signature stops tampering, but the header and claims are readable by anyone who holds the token. Putting personal data, internal identifiers or secrets in claims exposes them to every client, proxy and log that sees the token. Use encrypted tokens (JWE) or keep sensitive data server side. See the JWT Security Guide and the JWT and Session Tokens in Code and Logs Guide.

Encrypting passwords instead of hashing them

The OWASP Password Storage Cheat Sheet says passwords should be hashed, not encrypted, in almost all cases: encryption is two way, so whoever obtains the key obtains every password. Encryption is only appropriate where the application genuinely needs the original password, such as logging in to a legacy system with no delegated access; that is a secrets management problem, not password storage.

Fast hashes for passwords

OWASP warns that fast algorithms such as SHA-256, MD5 and SHA-1 let attackers test enormous numbers of guesses. A salted SHA-256 still falls quickly to offline cracking (ATT&CK T1110.002 Password Cracking). Current OWASP minimums:

AlgorithmWhen to useOWASP minimum parameters
Argon2idPreferred for new systemsm=19456 (19 MiB), t=2, p=1, or equivalent trade-offs such as m=12288, t=3, p=1
scryptWhere Argon2id is unavailableN=2^17 (128 MiB), r=8, p=1
bcryptLegacy systemsWork factor 10 or more; most implementations process only the first 72 bytes
PBKDF2Where FIPS-140 compliance is requiredHMAC-SHA256: 600,000 iterations; HMAC-SHA512: 220,000

Plain hashes used as integrity protection

Publishing a SHA-256 checksum next to a download on the same server detects corruption, but an attacker who can replace the file can replace the checksum too. Likewise, a webhook or API that "signs" requests with SHA256(body) proves nothing, because anyone can compute it. Use HMAC with a shared secret (and compare in constant time), or a digital signature where the verifier must not hold a signing secret. RFC 2104 recommends HMAC keys at least as long as the hash output, generated randomly and refreshed periodically.

Encoding as obfuscation in attacks

Attackers use the same tricks in reverse: Base64 encoded PowerShell, encoded command and control traffic (ATT&CK T1132 Data Encoding) and obfuscated payloads (T1027). Defenders should decode routinely during triage rather than treat encoded content as opaque. See MITRE ATT&CK T1132 Data Encoding.

Choosing the right one

You need toUseAvoid
Send binary data through a text channel (email, JSON, URL)Base64 or Base64url encodingThinking the result is hidden
Store a secret your application must use later (API key, database password)A secrets manager or KMS; if stored locally, AES-GCM with the key held elsewhereBase64 in config; key in the same repository as the ciphertext
Store user passwordsArgon2id (or scrypt, bcrypt, PBKDF2) with per-user salt; optional pepper in a vault or HSMEncryption; MD5, SHA-1 or SHA-256
Detect accidental corruption of a fileSHA-256 digestMD5 or SHA-1 for anything security relevant
Prove a message came from a partner and was not changedHMAC-SHA256 with a shared key, or a digital signatureUnkeyed hash
Protect data in transitTLS 1.2 or 1.3Custom encoding or home grown encryption
Protect data at rest in a database or bucketPlatform encryption with managed keys, plus access controlEncoding fields and calling them encrypted

Small vs large teams: a small team should rely on platform defaults: a language's standard password hashing library, the cloud provider's secrets manager and KMS, and TLS from the load balancer. Larger organisations add a central key management service, a cryptographic inventory and standard libraries that make the right choice the easy one. See the Cryptographic Key Management Guide.

Where identity fits

Most encoded secrets found in code are non-human credentials: service account passwords, API keys, registry tokens and cloud access keys. Fixing the encoding is not enough. Move the credential into a secrets manager, give the workload a short-lived identity where the platform supports it, and rotate anything that was ever committed. See the Secrets Management Guide.

How to fix it in an existing codebase

  1. Find: scan repositories, images and CI variables for Base64 and hex strings near words such as password, secret, token and key, with a scanner that decodes before matching.
  2. Classify: for each hit, decide whether it is a secret (move to a vault), a password store (migrate to a password hash) or genuinely public data.
  3. Rotate first: treat any decoded credential as exposed and rotate it before changing code.
  4. Migrate password hashes on login: verify against the old hash, then rehash with Argon2id and store the new value; for dormant accounts, wrap the old hash and force a reset.
  5. Prevent: add pre-commit and CI secret scanning, and a code review rule that flags base64 decoding of configuration values.
  6. Roll back safely: keep the old verification path for password hashes until migration metrics show it is unused, then remove it.

Detection and measurement

  • Number of encoded or plaintext secrets found per 100 repositories, trending down.
  • Median time from secret detection to rotation.
  • Percentage of user accounts whose password hash uses an approved algorithm and parameters.
  • Percentage of Kubernetes clusters with Secret encryption at rest configured.
  • Percentage of inbound webhooks and partner APIs verified with HMAC or signatures.

Framework mapping

FrameworkReferenceRelevance
NIST CSF 2.0PR.DS-01, PR.DS-02Protect data at rest and in transit
NIST SP 800-53 Rev. 5SC-13, SC-28, SC-8, IA-5, SI-7Cryptographic protection, data at rest, transmission, authenticator storage, integrity
ISO/IEC 27001:2022Annex A 8.24Use of cryptography
MITRE CWECWE-261Weak encoding for password
ATT&CKT1552.001, T1110.002, T1132, T1027Credentials in files, password cracking, data encoding, obfuscation

Common failure patterns

  • "It's encrypted" meaning Base64: credentials in config files, Helm values or Kubernetes manifests encoded and committed to source control.
  • Key next to the ciphertext: data encrypted with AES, with the key in the same file, repository or container image, which reduces encryption to encoding.
  • Legacy password hashes left in place: MD5 or unsalted SHA-1 hashes still in the user table years after new code moved on, because no migration was planned.
  • Integrity without a key: request signing or file verification using a plain hash an attacker can recompute.
  • Encryption without integrity: unauthenticated modes such as CBC without a MAC, or ECB, which leak patterns and allow tampering.
  • Sensitive data in token claims: personal data placed in JWT payloads on the assumption that a signed token is private.

Practitioner checklist

  • Never describe encoded data as protected in code, documentation or audit evidence.
  • Scan repositories and images for encoded secrets with a scanner that decodes Base64.
  • Store application secrets in a secrets manager or KMS, never in encoded config.
  • Hash passwords with Argon2id or another OWASP-listed algorithm at current parameters.
  • Plan and track migration of legacy password hashes on next login.
  • Use authenticated encryption (AES-GCM or ChaCha20-Poly1305) for anything you encrypt yourself.
  • Use HMAC or signatures, compared in constant time, wherever integrity matters against an attacker.
  • Enable encryption at rest for Kubernetes Secrets and restrict who can read them.
  • Keep sensitive data out of JWT claims unless the token is encrypted.

Standards and references

Related NHI Mgmt Group resources: Encryption vs Hashing vs Masking · Hashing Guide · Cryptography Basics Guide · Secrets Management Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.