|
@@ -369,22 +369,31 @@ public class ToolsUtils {
|
|
|
}
|
|
|
|
|
|
public static String EncoderByMd5New(String str) {
|
|
|
- StringBuffer sb = new StringBuffer(32);
|
|
|
- try
|
|
|
+ StringBuilder pwd = new StringBuilder("");
|
|
|
+ try {
|
|
|
+ MessageDigest md = MessageDigest.getInstance("MD5");// 生成一个MD5加密计算摘要
|
|
|
+ byte[] digest1 = md.digest(str.getBytes("gb2312"));
|
|
|
+// byte[] digest1 = passord.getBytes("UTF-16LE");
|
|
|
+ for (int i = 0; i < digest1.length; i++)
|
|
|
{
|
|
|
- MessageDigest md = MessageDigest.getInstance("MD5");
|
|
|
- byte[] array = md.digest(str.getBytes("gb2312"));
|
|
|
-
|
|
|
- for (int i = 0; i < array.length; i++)
|
|
|
- {
|
|
|
- sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100)
|
|
|
- .toUpperCase().substring(1, 3));
|
|
|
+ //将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
|
|
|
+// pwd = pwd + digest1[i].toString("x");
|
|
|
+ int v = digest1[i] & 0xFf;
|
|
|
+ String hv = Integer.toHexString(v);
|
|
|
+ if (hv.length() < 2) {
|
|
|
+ pwd.append(0);
|
|
|
}
|
|
|
- } catch (Exception e)
|
|
|
- {
|
|
|
- return null;
|
|
|
+ pwd.append(hv);
|
|
|
+ }
|
|
|
+ } catch (NoSuchAlgorithmException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- return sb.toString().toLowerCase();
|
|
|
+// MD5 md5 = new MD5CryptoServiceProvider();
|
|
|
+ return pwd.toString();
|
|
|
}
|
|
|
|
|
|
public static String EncoderByMd5(String str) {
|
|
@@ -553,14 +562,18 @@ public class ToolsUtils {
|
|
|
return tempPKey;
|
|
|
}
|
|
|
|
|
|
- private static String MD5PubHasher(byte[] hashText) throws NoSuchAlgorithmException {
|
|
|
- MessageDigest md5 = MessageDigest.getInstance("MD5");
|
|
|
- byte[] b = md5.digest(hashText);
|
|
|
- StringBuilder ret = new StringBuilder();
|
|
|
- for (int i = 0; i < b.length; i++) {
|
|
|
- ret.append(String.format("%02x", b[i]));
|
|
|
+ public static String MD5PubHasher(byte[] hashText) {
|
|
|
+ try {
|
|
|
+ MessageDigest md5 = MessageDigest.getInstance("MD5");
|
|
|
+ byte[] b = md5.digest(hashText);
|
|
|
+ StringBuilder ret = new StringBuilder();
|
|
|
+ for (int i = 0; i < b.length; i++) {
|
|
|
+ ret.append(String.format("%02x", b[i]));
|
|
|
+ }
|
|
|
+ return ret.toString();
|
|
|
+ }catch (NoSuchAlgorithmException e){
|
|
|
+ return null;
|
|
|
}
|
|
|
- return ret.toString();
|
|
|
}
|
|
|
|
|
|
public static String encryptDes(String source, byte[] key, byte[] iv) throws Exception {
|