Meaningless Drivel is fun!*
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
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Encryption:Generate MD5 hash in Java -Output 16 character
 
Similar Threads
Fastest way of calculating MD5
how to convert MD5 encoded string back to plain text
problem in MD5 encryption and Decryption
Fastest way of calculating MD5
MD5 output?