com.baidu.haotianjing.core.auth.MD5SignerImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of haotianjing-java-sdk Show documentation
Show all versions of haotianjing-java-sdk Show documentation
Haotianjing SaaS SDK for Java
The newest version!
package com.baidu.haotianjing.core.auth;
import org.apache.commons.codec.digest.DigestUtils;
import java.util.Arrays;
import java.util.Map;
import static com.baidu.haotianjing.core.constants.RiskCoreConstants.ACCOUNTID;
import static com.baidu.haotianjing.core.constants.RiskCoreConstants.APPKEY;
import static com.baidu.haotianjing.core.constants.RiskCoreConstants.MODE;
/**
* 签名生成器 - MD5算法
*/
public class MD5SignerImpl implements Signer {
public static final MD5SignerImpl INSTANCE = new MD5SignerImpl();
private MD5SignerImpl() {
}
@Override
public String sign(Credentials credentials, String mode, Map params) {
String accountId = credentials.getAccountId();
String appkey = credentials.getAppkey();
String seckey = credentials.getSeckey();
// 1. 参数升序排序
String[] keys = params.keySet().toArray(new String[0]);
Arrays.sort(keys);
// 2. 拼接参数名和参数值
StringBuilder sb = new StringBuilder();
sb.append(ACCOUNTID).append(accountId);
sb.append(APPKEY).append(appkey);
sb.append(MODE).append(mode);
for (String key : keys) {
Object val = params.get(key);
if (null == val) {
continue;
}
sb.append(key).append(val);
}
// 3. 带上seckey
sb.append(seckey);
return DigestUtils.md5Hex(sb.toString());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy