MD5 Hash : MD5.xml « Security « Android






MD5 Hash

 
// Created by plusminus on 10:35:21 - 01.02.2009
//package org.andnav2.util;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


class MD5 {

  public static String hash(final String in) {
    if(in == null) {
      throw new IllegalArgumentException("'in' has to be != null");
    }
    try {
      final MessageDigest md5 = MessageDigest.getInstance("MD5");
      if(md5 == null) {
        return in;
      }

      try {
        md5.update(in.getBytes("UTF-8"));
      } catch (final UnsupportedEncodingException e) {
        return in;
      }

      return new BigInteger(1,md5.digest()).toString(16);
    } catch (final NoSuchAlgorithmException ex) {
      return in;
    }
  }
}

   
  








Related examples in the same category

1.Md5 sum
2.MD5 hash generator.
3.md5 sum and hmac Sha1 Digest
4.Create Md5 Checksum
5.MD5 String Util
6.Download from URL and MD5 check
7.Md5 Hash and MessageDigest
8.Md5 String