Information Security 8 min read

Understanding Hash Functions, Encryption Algorithms, and Their Java Implementation

This article explains the fundamentals of hash functions and encryption algorithms, illustrates Google’s SHA‑1 collision breakthrough, describes the classification of cryptographic methods, presents a detailed end‑to‑end encryption/decryption scenario, and shows how Java’s built‑in APIs and libraries support these techniques for secure data handling.

360 Quality & Efficiency
360 Quality & Efficiency
360 Quality & Efficiency
Understanding Hash Functions, Encryption Algorithms, and Their Java Implementation

Recently Google demonstrated a SHA‑1 collision by creating two different PDF files with identical SHA‑1 hashes, highlighting that SHA‑1 is theoretically broken but costly to attack.

Hash functions are crucial for browser security, code repository integrity, and file verification. Google’s effort pushes the industry toward more secure alternatives, and the author uses this news to introduce Java encryption and decryption techniques for beginners.

1. Classification of encryption algorithms

In cryptography, algorithms are divided into one‑way (hash) algorithms, symmetric encryption algorithms, and asymmetric encryption algorithms. One‑way algorithms such as MD5 and SHA provide data integrity verification; symmetric algorithms like DES encrypt stored data; asymmetric algorithms such as RSA secure data transmission.

One‑way algorithms rely on hash functions that produce a digest that cannot be reversed. Users can compare the computed hash of a downloaded file with the hash published on the vendor’s site to detect tampering. The overall verification flow is shown in Figure 1.

Symmetric encryption uses a single shared key for both encryption and decryption. Because the same key is used, the process is fast and suitable for encrypting stored data, though key management becomes complex as the number of participants grows. Figure 2 illustrates this concept.

2. Applications of encryption algorithms

To achieve confidentiality, non‑repudiation, and integrity in Internet communications, the author presents a practical scenario.

Scenario : User A (Xiaoming) needs to send confidential information to User B (Xiaowang) from different companies.

Encryption process :

1. A hashes the message (e.g., MD5 or SHA‑256) to obtain a digital signature (signKey1).

2. A generates an RSA key pair, encrypts signKey1 with the private key, producing an encrypted signature and data.

3. A creates a random DES key, encrypts the signed data with DES, yielding the ciphertext and the symmetric key.

4. A encrypts the DES key with B’s RSA public key and sends the combined package.

Decryption process :

1. B uses his RSA private key to recover the DES key.

2. B decrypts the ciphertext with the DES key to obtain the signed data.

3. B uses A’s RSA public key to decrypt the digital signature, retrieving signKey1.

4. B hashes the received message to obtain signKey2 and compares it with signKey1 to verify integrity.

The combined use of MD5 for integrity, DES for data encryption, and RSA for authentication satisfies the basic security goals.

3. Java support for encryption algorithms

Java provides extensive cryptographic support: the MessageDigest class implements MD5 and SHA, the Cipher class handles DES, AES, RSA, and DSA, and third‑party libraries such as Apache Commons Codec, Bouncy Castle, and others extend algorithm coverage and key‑size options.

4. Conclusion

The article briefly introduced the classification of encryption algorithms and a typical end‑to‑end encryption workflow, aiming to help readers understand cryptographic concepts and avoid privacy leaks in today’s data‑driven Internet.

javaencryptioninformation securitycryptographyhash functions
360 Quality & Efficiency
Written by

360 Quality & Efficiency

360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.