8f7d101ee2fee8ccc1fef0538ddda2f731e18e62.svn-base 845 B

1234567891011121314151617181920212223242526272829303132333435
  1. package com.sinosoft.am.userUtil;
  2. import java.security.MessageDigest;
  3. import java.security.NoSuchAlgorithmException;
  4. import org.apache.commons.net.util.Base64;
  5. public class UserUtil {
  6. public static String md5(String msg){
  7. String result = "";
  8. if(msg==null){
  9. return result;
  10. }
  11. try {
  12. MessageDigest md = MessageDigest.getInstance("MD5");
  13. MessageDigest.getInstance("MD5");
  14. byte[] output = md.digest(msg.getBytes());
  15. System.out.println(output.toString());
  16. result = Base64.encodeBase64String(output).trim();
  17. //System.out.println(result);
  18. return result;
  19. } catch (NoSuchAlgorithmException e) {
  20. e.printStackTrace();
  21. }
  22. return result;
  23. }
  24. public static void main(String[] args){
  25. System.out.println(md5("nwyj123456"));
  26. //System.out.println(md5("abcsssssssssssxxxxx")); wZ1sb/mFufbA99q6evnD4A==
  27. }
  28. }