Digital Stronghold - Software Engineering, Musicality and Facts of Life…



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!

January 1, 2009

Happy New Year!

Filed under: Progressive Studies

Welcome 2009!

Plurk with me, http://www.plurk.com/eradicus
See my multiply account, http://eradicus.multiply.com

Prospero año nuevo!

Theme designed by Joset Anthony Zamora


Digital Stronghold

↑ Get Headline Animator