• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Encryption:Generate MD5 hash in Java -Output 16 character

 
pappitha swaminathan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2675
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds odd. If memory serves, MD5 creates 128 bits out output - 16 bytes, each consisting of a hex character.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic