Android代码库-MD5加密

来源:互联网 发布:linux vi定位到某一行 编辑:程序博客网 时间:2024/06/12 01:27

方法一:

import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;public class Md5Encoder {public String encode(String pwd) throws NoSuchAlgorithmException {MessageDigest digest = MessageDigest.getInstance("MD5");byte[] bytes = digest.digest(pwd.getBytes());StringBuffer sb = new StringBuffer();for (int i = 0; i < bytes.length; i++) {String s = Integer.toHexString(0xff & bytes[i]);//只留后两位if (s.length() == 1) {sb.append("0" + s);} elsesb.append(s);}return sb.toString();}}


0 0
原创粉丝点击