• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Encryption:Generate MD5 hash in Java -Output 16 character

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic