Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to encode string using MD5 in Java?

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 394
    Comment on it

    Generally we need to encode the password in our Applications for security purpose and we can use MD5 for this purpose.

    Example - In the below method I'm encoding sting by using MD5

    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    
        /**
         * This method encode the provided string
         *
         * @param text
         * @return
         */
        public static String MD5ToString(String salt)
        {
            MessageDigest md = null;
            try
            {
                md = MessageDigest.getInstance("MD5");
            }
            catch (NoSuchAlgorithmException e)
            {
                e.printStackTrace();
            }
            md.update(salt.getBytes());
    
            byte byteData[] = md.digest();
    
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < byteData.length; i++)
                sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
    
            return sb.toString();
        }

    Hope this will help you :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: