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.     } 

 

奶牛 | 2013年03月15日
  • 寒兰泡 2014年01月13日 at 12:21 下午
    :gz :good :k :wx :k :wx :wx :gz :gz :gz :gz :gz :gz :gz :fd :fd :fd :good :good :good :good :k :k :k :k :k :k :wx :wx :wx :wx :wx :wx :fd :fd
  • 寒兰泡 2014年01月13日 at 12:22 下午
    :bs :bs :bs :bs
Comments are closed.