MD5 Authentication Technique in Java – Message Digest
Now a days it is so common that all the user passwords go through a authentication process before it gets stored in the database. One of the most common technique is MessageDigest (MD5) technique.

First let us try to understand what Message Digest is,

What is Message Digest?
MessageDigest is a java class for algorithms such as SHA-1 or SHA-256. Please note that MessageDigest(MD5) is a secure one-way hash function.

What is meant by SHA-1 / SHA-256?
SHA stands for Secure Hash Algorithm is a series of cryptographic hash algorithms designed by NSA – USA. SHA-1 is commonly displayed as 40 character Hexa-decimal number. SHA-256 cryptographic algorithms, single aimed hash functions. SHA-2 family consists of SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256. (Source)

Please note that, MD5 Hashing technique is Not Recommended Technique as hackers can easily decrypt the password

MD5 is one-way hashing function, that is you can encrypt the password using code, But you cannot decrypt with the code.

Now let us see an example for MD5 Technique,

public class md5 {
    public static void main(String[] args) 
        String password = "javainfinite";
        String Hashedpassword = null;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5"); //Message Digest class
            byte[] bytes = md.digest();
            StringBuilder sb = new StringBuilder();
            for(int i=0; i< bytes.length ;i++)
                sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1)); //Hexa-Decimal character operations
            Hashedpassword = sb.toString();
        catch (Exception e) 




By Sri

Leave a Reply

Your email address will not be published. Required fields are marked *