赞
踩
- 标准中定义的算法简单点说就是:
- 1. 先计算MD5加密的二进制数组(128位)。
- 2. 再对这个二进制进行base64编码(而不是对32位字符串编码)。
需要32位的md5转换
- public static String base64ForMD5(String md5str) {
- if (TextUtils.isEmpty(md5str) || md5str.length() != 32) {
- return null;
- }
- byte[] disgist = new byte[16];
- int number;
- for (int idx = 0; idx < 16; idx++) {
- String substring = md5str.substring(idx * 2, idx * 2 + 2);
- number = Integer.parseInt(substring, 16);
- disgist[idx] = (byte) number;
- }
- return new String(Base64.encode(disgist, Base64.DEFAULT)).trim();
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。