java MD5 32位加密
程序员文章站
2024-03-16 18:15:46
...
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5 {
public static void main(String[] args) {
MD5 md5 = new MD5();
String ss = md5.encryption("10012843443");
System.err.print(ss);
}
public String encryption(String OrderNo) {
String result = OrderNo+"354039456123789"+"andriod";
String re_md5 = new String();
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(result.getBytes());
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
re_md5 = buf.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return re_md5.toUpperCase();
}
}
MD5加密后生成32位长度字符串并转换成大写