my blog my blog

Tag: apache.commons.codec
Java调用Apache commons codec实现md5加密

 

org.apache.commons.codec.digest
Class DigestUtils

java.lang.Object
  extended by org.apache.commons.codec.digest.DigestUtils

static String md5Hex(String data)
          Calculates the MD5 digest and returns the value as a 32 character hex string.

apache commons codec下载:http://commons.apache.org/proper/commons-codec/download_codec.cgi

实现方法:

  1. import org.apache.commons.codec.digest.*; 
  2.  
  3. public class md5another { 
  4.     public void md5create(String input) { 
  5.         System.out.print("32bit result:" + DigestUtils.md5Hex(input) + "\n"); 
  6.         System.out.print("16bit result:" 
  7.                 + DigestUtils.md5Hex(input).substring(824) + "\n"); 
  8.     } 
  9.  
  10.     public static void main(String[] args) { 
  11.  
  12.         md5another a = new md5another(); 
  13.         a.md5create("nenew"); 
  14.     }