我们正在使用下面的java方法来支持HMAC->SHA1 1 signature.But,它显示的签名在sso console.Please中不匹配,试着在这个issue.let中提供帮助,我知道在java.What方法中是否还有其他方法被disqus使用以从消息和时间戳生成签名-
/**
* To convert into base16
*
* @param bytes
* @return
*/
private static String toHexString(byte[] bytes) {
Formatter formatter = new Formatter();
for (byte b : bytes) {
formatter.format("%02x", b);
}
return formatter.toString();
}
/**
*
* @param data
* @param key
* @return
* @throws SignatureException
* @throws NoSuchAlgorithmException
* @throws InvalidKeyException
*/
public static String calculateRFC2104HMAC(String data, String key)
throws SignatureException, NoSuchAlgorithmException,
InvalidKeyException {
final String HMAC_SHA1_ALGORITHM = "HmacSHA1";
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(),
HMAC_SHA1_ALGORITHM);
Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
mac.init(signingKey);
return toHexString(mac.doFinal(data.getBytes()));
//return DatatypeConverter.printBase64Binary(mac.doFinal(data.getBytes()));
}参考资料:Disqus sso java
发布于 2015-10-18 05:32:31
Hmac sha1方法返回加密消息的十六进制字符串,我必须确保我们传递给该方法的密钥是正确的。它解决了问题。
https://stackoverflow.com/questions/31803686
复制相似问题