在Java中输出相同值的C ++中的HMAC

时间:2016-09-29 20:45:20

标签: java c++ hmac

我无法在C ++中从HMAC获得相同的输出,就像我在java中编写的那样,它们有不同的输出。

的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;

0 个答案:

没有答案