This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Distributed Java and the fly likes Encryption:Generate MD5 hash in Java -Output 16 character Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Encryption:Generate MD5 hash in Java -Output 16 character" Watch "Encryption:Generate MD5 hash in Java -Output 16 character" New topic
Author

Encryption:Generate MD5 hash in Java -Output 16 character

pappitha swaminathan
Greenhorn

Joined: Aug 16, 2011
Posts: 9
Hi All,

I want to generate output of 16 character using MD5 algorithm. general output while performing the function is 128 bit. i have reduced it to 20character using BASE64.

here is the code:

public class MD5Algorithm{
public static void main(String args[]){
String password="Welcome";

MessageDigest md;
try {
md = MessageDigest.getInstance("MD5");
final byte[] md5Digest = md.digest(password.getBytes());
final BigInteger md5Number = new BigInteger(1, md5Digest);
final String md5String = md5Number.toString();
// print out the digest in base64
BASE64Encoder encoder = new BASE64Encoder();
String base64 = encoder.encode(md5Digest);
System.out.println(base64);
}

Please help me for getting the output.

thanks in advance.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
This sounds odd. If memory serves, MD5 creates 128 bits out output - 16 bytes, each consisting of a hex character.
 
jQuery in Action, 2nd edition
 
subject: Encryption:Generate MD5 hash in Java -Output 16 character