md5加密的一段小代码

来源:互联网 发布:ubuntu 16.04软件商店 编辑:程序博客网 时间:2024/05/21 01:52

 public static String generatemd5string(String csinput) {
  byte[] b, b2;
  StringBuffer buf;
  String csreturn = null;

  try {
   b = csinput.getBytes("iso-8859-1");
   MessageDigest md = MessageDigest.getInstance("MD5");
   md.update(b);
   b2 = md.digest();

   buf = new StringBuffer(b2.length * 2);
   for (int nLoopindex = 0; nLoopindex < b2.length;

   nLoopindex++) {
    if (((int) b2[nLoopindex] & 0xff) < 0x10) {
     buf.append("0");
    }
    buf.append(Long.toString((int) b2[nLoopindex] & 0xff,

    16));
   }
   csreturn = new String(buf);
  } catch (Exception e) {
   e.printStackTrace();
   csreturn = null;
  }

  return csreturn;
 }

 

 

//瞎写的最最简单的加密方法

 

 public String stringChange(String s)
 {
  String str= s;
  char[] ch = str.toCharArray();
  for(int i=0;i<ch.length;i++)
  {
   ch[i] = (char) (ch[i]+1);
  }
  
  str = ch.toString();
  
  return str;
 }