Digital Stronghold




January 27, 2009

MD5 Encryption in Java

This is useful for storing passwords in a database though still vulnerable to md5 dictionary attacks, anyway, here’s a static method.

public static String encrypt(String text) {
        String ecryptedText = "";
        try {
                MessageDigest md5Encrypt = MessageDigest.getInstance("MD5");
                md5Encrypt.update(text.getBytes(), 0, text.length());
                ecryptedText = new BigInteger(1, md5Encrypt.digest()).toString(16);
        }  catch (NoSuchAlgorithmException exception) {
                exception.printStackTrace();
        }
        return ecryptedText;
}

This will return the MD5-encrypted string. Have a great day!

1 Comment »

The URI to TrackBack this entry is: http://eradicus.blogsome.com/2009/01/27/md5-encryption-in-java/trackback/

  1. Hey, that was interesting,

    but how can we prevent vulnerablity of md5 dictionary attacks?

    Thanks for writing about it

    Comment by software development uk — August 18, 2009 @ 3:58 pm

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Theme designed by Joset Anthony Zamora


Digital Stronghold

↑ Get Headline Animator