当前位置 : 主页 > 网络编程 > PHP >

java md5加密和base64加密方法

来源:互联网 收集:自由互联 发布时间:2023-09-07
md5加密 private String md5Encode(String plainText) { String re_md5 = new String(); try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(plainText.getBytes()); byte b[] = md.digest(); int i; StringBuffer buf = new StringBuf


md5加密

private String md5Encode(String plainText) {
String re_md5 = new String();
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(plainText.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;
}

base64加密

// import sun.misc.BASE64Encoder;

BASE64Encoder encoder = new BASE64Encoder();
String password = "aaaa" + password + "bbbbb";
String password64 = encoder.encode(password.getBytes());


网友评论