0Pricing
Java Academy · Lesson

Cryptographic Hashing with MessageDigest

Hash passwords with SHA-256, add salt to prevent rainbow table attacks, and compare digests securely.

What Is Cryptographic Hashing?

A cryptographic hash function maps data of any size to a fixed-size digest. It is one-way (cannot be reversed), deterministic, and collision-resistant. Used for password storage, data integrity, and digital signatures.

MessageDigest API

MessageDigest.getInstance("SHA-256") returns a SHA-256 digester. Call digest(bytes) to compute the hash and get a byte array.

MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] hash = md.digest("password123".getBytes(StandardCharsets.UTF_8));
String hex = HexFormat.of().formatHex(hash);
System.out.println(hex); // 64-char hex string

All lessons in this course

  1. Cryptographic Hashing with MessageDigest
  2. AES Symmetric Encryption
  3. HMAC-SHA256 for Message Integrity
  4. JWT: Structure, Creation, and Verification
← Back to Java Academy