首页 > 代码库 > MD5的加密和解密(总结)

MD5的加密和解密(总结)

效果图如下:



package com.test;
import java.security.MessageDigest;

public class MD5 {

 // MD5加码。32位
 public static String MD5(String inStr) {
  MessageDigest md5 = null;
  try {
   md5 = MessageDigest.getInstance("MD5");
  } catch (Exception e) {
   System.out.println(e.toString());
   e.printStackTrace();
   return "";
  }
  char[] charArray = inStr.toCharArray();
  byte[] byteArray = new byte[charArray.length];

  for (int i = 0; i < charArray.length; i++)
   byteArray[i] = (byte) charArray[i];

  byte[] md5Bytes = md5.digest(byteArray);

  StringBuffer hexValue = http://www.mamicode.com/new StringBuffer();>