记得上下班打卡 | git大法好,push需谨慎

Commit 52359170 authored by 姜秀龙's avatar 姜秀龙

paysign 31位修复

parent f8932630
package com.liquidnet.commons.lang.util; package com.liquidnet.commons.lang.util;
import java.math.BigInteger;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
...@@ -20,20 +19,13 @@ public class MD5Utils { ...@@ -20,20 +19,13 @@ public class MD5Utils {
* 使用md5的算法进行加密 * 使用md5的算法进行加密
*/ */
public static String md5(String plainText) { public static String md5(String plainText) {
byte[] secretBytes = null;
try { try {
secretBytes = MessageDigest.getInstance("md5").digest(plainText.getBytes(Charset.defaultCharset())); byte[] secretBytes = MessageDigest.getInstance("md5").digest(plainText.getBytes(Charset.defaultCharset()));
// 不可使用 BigInteger.toString(16):会吞掉高位为 0 的半字节/整字节,导致 MD5 非固定 32 位十六进制(微信二次签名会偶发失败)
return bufferToHex(secretBytes);
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new RuntimeException("没有md5这个算法!"); throw new RuntimeException("没有md5这个算法!");
} }
String md5code = new BigInteger(1, secretBytes).toString(16);// 16进制数字
// 如果生成数字未满32位,需要前面补0
if (md5code.length() < 32) {
for (int i = 0; i <= 32 - md5code.length(); i++) {
md5code = "0" + md5code;
}
}
return md5code;
} }
protected static MessageDigest messagedigest = null; protected static MessageDigest messagedigest = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment