我无法在C ++中从HMAC获得相同的输出,就像我在java中编写的那样,它们有不同的输出。
private static byte[] hmac_sha(String crypto, byte[] keyBytes, byte[] text) {
try {
Mac hmac;
hmac = Mac.getInstance(crypto);
SecretKeySpec macKey = new SecretKeySpec(keyBytes, "RAW");
hmac.init(macKey);
return hmac.doFinal(text);
} catch (GeneralSecurityException gse) {
throw new UndeclaredThrowableException(gse);
}
}
C ++:
BYTE *key = (BYTE *)encodedSeed.data();
BYTE digest[20];
const char *message = encodedTime.data();
CHMAC_SHA1 HMAC;
HMAC.HMAC_SHA1((BYTE *)message, strlen(message), key, sizeof(key), digest);
wstring finalDigest;
for (int i = 0; i < 20; i++){
finalDigest.push_back(std::btowc(digest[i]));
}
return finalDigest;