Package com.luna.common.encrypt
Class SignUtil
java.lang.Object
com.luna.common.encrypt.SignUtil
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
generateSignature
(Map<String, String> data, String key) 生成签名static String
generateSignature
(Map<String, String> data, String key, SignUtil.SignType signType) 生成签名.static String
generateSignedXml
(Map<String, String> data, String key) 生成带有 sign 的 XML 格式字符串static String
generateSignedXml
(Map<String, String> data, String key, SignUtil.SignType signType) 生成带有 sign 的 XML 格式字符串static String
hmacsha256
(String data, String key) 生成 HMACSHA256static boolean
isSignatureValid
(String xmlStr, String key) 判断签名是否正确static boolean
isSignatureValid
(Map<String, String> data, String key) 判断签名是否正确,必须包含sign字段,否则返回false。使用MD5签名。static boolean
isSignatureValid
(Map<String, String> data, String key, SignUtil.SignType signType) 判断签名是否正确,必须包含sign字段,否则返回false。
-
Field Details
-
MD5
- See Also:
-
FIELD_SIGN
- See Also:
-
-
Constructor Details
-
SignUtil
public SignUtil()
-
-
Method Details
-
generateSignedXml
生成带有 sign 的 XML 格式字符串- Parameters:
data
- Map类型数据key
- API密钥- Returns:
- 含有sign字段的XML
- Throws:
Exception
-
generateSignedXml
public static String generateSignedXml(Map<String, String> data, String key, SignUtil.SignType signType) throws Exception生成带有 sign 的 XML 格式字符串- Parameters:
data
- Map类型数据key
- API密钥signType
- 签名类型- Returns:
- 含有sign字段的XML
- Throws:
Exception
-
isSignatureValid
判断签名是否正确- Parameters:
xmlStr
- XML格式数据key
- API密钥- Returns:
- 签名是否正确
- Throws:
Exception
-
isSignatureValid
判断签名是否正确,必须包含sign字段,否则返回false。使用MD5签名。- Parameters:
data
- Map类型数据key
- API密钥- Returns:
- 签名是否正确
- Throws:
Exception
-
isSignatureValid
public static boolean isSignatureValid(Map<String, String> data, String key, SignUtil.SignType signType) throws Exception判断签名是否正确,必须包含sign字段,否则返回false。- Parameters:
data
- Map类型数据key
- API密钥signType
- 签名方式- Returns:
- 签名是否正确
- Throws:
Exception
-
generateSignature
生成签名- Parameters:
data
- 待签名数据key
- API密钥- Returns:
- 签名
- Throws:
Exception
-
generateSignature
public static String generateSignature(Map<String, String> data, String key, SignUtil.SignType signType) throws Exception生成签名. 注意,若含有sign_type字段,必须和signType参数保持一致。- Parameters:
data
- 待签名数据key
- API密钥signType
- 签名方式- Returns:
- 签名
- Throws:
Exception
-
hmacsha256
生成 HMACSHA256- Parameters:
data
- 待处理数据key
- 密钥- Returns:
- 加密结果
- Throws:
Exception
-