工具
MD5工具
使用MD5工具计算和验证Hash值。
MD5 代码示例如下
使用Java生成MD5签名示例
copy
package com.alipay.iopentools;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* MD5 encryption/authentication tool class
*/
public class MD5Utils1 {
/**
* String encrypted to MD5 without salt
*
* @param plainText Pass in the string to be encrypted
* @return Generate 32-bit (lowercase letters + numbers) string after MD5 encryption
*/
public static String MD5Lower(String plainText) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(plainText.getBytes());
return new BigInteger(1, md.digest()).toString(16);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
/**
* Test
*
* @param args
*/
public static void main(String[] args) {
String sign_data = "partnerId=*****&extBizPartnerId=*****&redirectUrl=*****&referenceCustomerId=*****&storeUrl=*****&storeName=*****p¤cy=USD&requestId=*****&key=*****@***.***";
String signature = MD5Lower(sign_data);
System.out.println(signature);
}
}
使用Linux命令行生成MD5签名示例
copy
echo -n "partnerId=*****&extBizPartnerId=*****&redirectUrl=*****&referenceCustomerId=*****&storeUrl=*****&storeName=*****p¤cy=USD&requestId=*****&key=*****@***.***" | md5sum