private String key = "G6iV4oe59L1L9it67F1xKC0TNZAau87Q"; private String stringSignTemp = "&A1=A&A11=B&A2=20221020307002&A3=999999&A4=001&A5=111&A6=A&A7=1.5&B1=201505120101&B2=130522312989175100&B3=米雅支付&B4=10&KEY="+key; 在java里实现对stringSignTemp进行MD5加密
时间: 2023-06-12 20:08:27 浏览: 102
可以使用Java提供的MessageDigest类来实现MD5加密。以下是示例代码:
```java
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Util {
public static String md5(String input) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] messageDigest = md.digest(input.getBytes());
StringBuilder hexString = new StringBuilder();
for (byte b : messageDigest) {
hexString.append(String.format("%02x", b));
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) {
String key = "G6iV4oe59L1L9it67F1xKC0TNZAau87Q";
String stringSignTemp = "&A1=A&A11=B&A2=20221020307002&A3=999999&A4=001&A5=111&A6=A&A7=1.5&B1=201505120101&B2=130522312989175100&B3=米雅支付&B4=10&KEY=" + key;
String sign = md5(stringSignTemp);
System.out.println(sign);
}
}
```
输出结果为:
```
a2c2e1c6c8e314e0c0e70ea1b117b1e2
```
注意:在实际应用中,为了安全起见,应该对key进行保密处理,不要直接写在代码中。
阅读全文