Encode String to MD5 Encryption

Posted: April 27, 2009 in Java, Programming
Tags: , ,

In cryptography, MD5 (Message-Digest algorithm 5) is a widely used cryptographic hash function with a 128-bit hash value. As an Internet standard (RFC 1321), MD5 has been employed in a wide variety of security applications, and is also commonly used to check the integrity of files. However, it has been shown that MD5 is not collision resistant; as such, MD5 is not suitable for applications like SSL certificates or digital signatures that rely on this property. An MD5 hash is typically expressed as a 32 digit hexadecimal number.

package md5;

import java.security.MessageDigest;

public class Main
{
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception
{
String passwd = “azer89”;

MessageDigest m = MessageDigest.getInstance(“MD5”);
m.update(passwd.getBytes(“UTF8”));
byte s[] = m.digest();
String result = “”;
for (int i = 0; i < s.length; i++) { result += Integer.toHexString((0x000000ff & s[i]) | 0xffffff00).substring(6); } System.out.println(result); } } [/sourcecode] Source : http://en.wikipedia.org/wiki/MD5

Comments
  1. Ashraf Bashir says:

    Thanks :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s