https://github.com/shaina-gh/md5-mac
A Java-based tool to generate secure Message Authentication Codes (MACs) using HMAC-MD5 for verifying data integrity and authenticity. Features MD5 hashing, RFC 2104-compliant key adjustment, and inner/outer hash computation with ipad/opad. Ideal for learning cryptographic integrity checks, with sample key-message inputs and hex-encoded output.
https://github.com/shaina-gh/md5-mac
cryptography hashing java mac
Last synced: about 1 month ago
JSON representation
A Java-based tool to generate secure Message Authentication Codes (MACs) using HMAC-MD5 for verifying data integrity and authenticity. Features MD5 hashing, RFC 2104-compliant key adjustment, and inner/outer hash computation with ipad/opad. Ideal for learning cryptographic integrity checks, with sample key-message inputs and hex-encoded output.
- Host: GitHub
- URL: https://github.com/shaina-gh/md5-mac
- Owner: shaina-gh
- Created: 2025-04-15T15:55:26.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-15T16:15:12.000Z (about 1 year ago)
- Last Synced: 2025-06-06T20:41:33.652Z (about 1 year ago)
- Topics: cryptography, hashing, java, mac
- Language: Java
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ HMAC-MD5 Implementation in Java
---
### ๐ Author : Shaina
---
## ๐ง What is HMAC-MD5?
HMAC (Hash-based Message Authentication Code) is a mechanism for verifying data integrity and authenticity using a cryptographic hash function (MD5 in this case). MD5 (Message Digest Algorithm 5) produces a 128-bit hash value, commonly used to validate data integrity. HMAC combines a secret key with the message and applies the hash function twice for enhanced security.
---
## **MD5 Core Operations**:
- **Padding**: Adjust message length to align with 512-bit blocks.
- **Block Processing**: Divide into 512-bit chunks and process via four rounds of bitwise operations.
- **Bitwise Functions**: Non-linear functions (AND, OR, XOR, NOT) applied during rounds.
- **Final Digest**: 128-bit output after processing all blocks.
---
## **HMAC-MD5 Steps**:
1. **Key Preparation**: Adjust key length to 64 bytes.
2. **Inner/Outer Padding**: XOR key with `ipad` (0x36) and `opad` (0x5C).
3. **Hashing**: Compute hash of `(key โ ipad) + message`, then hash `(key โ opad) + inner_hash`.
---
## ๐ฏ Objective
This project demonstrates HMAC-MD5 for generating a Message Authentication Code (MAC) in Java, featuring:
- MD5 hash function implementation.
- HMAC key adjustment and padding.
- Hex-encoded MAC output for verification.
---
## ๐ ๏ธ Features
- HMAC-MD5 implementation compliant with RFC 2104.
- Key handling (truncation/padding to 64 bytes).
- Padding logic for MD5 alignment.
- Hex string conversion for digest output.
---
## ๐งช HMAC-MD5 Procedure
1. **Key Adjustment**:
- Truncate keys longer than 64 bytes to MD5 hash.
- Pad shorter keys with zeros to 64 bytes.
2. **Inner Hash**:
- XOR key with `ipad` (0x36).
- Compute MD5 hash of `ipad + message`.
3. **Outer Hash**:
- XOR key with `opad` (0x5C).
- Compute MD5 hash of `opad + inner_hash`.
4. **MAC Output**: Convert final hash to a 32-character hex string.
---
## โถ๏ธ How to Compile & Run
```bash
javac HMACMD5.java
java HMACMD5
```
---