Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hmac_sha256 incorrect #63

Closed
Cyvadra opened this issue May 19, 2020 · 2 comments
Closed

hmac_sha256 incorrect #63

Cyvadra opened this issue May 19, 2020 · 2 comments

Comments

@Cyvadra
Copy link

Cyvadra commented May 19, 2020


julia> tmp_key = rand(UInt8,16);

julia> str = "123";

julia> bytes2hex( SHA.hmac_sha256(tmp_key,str) )
"ce0006ef9b02c5c710b8bfcb47e6f5177b44323992e2918dfbdb087a03ec6f4f"

julia> bytes2hex(tmp_key)
"e85726cc1b12609bbaebe535f0926f59"

where the correct answer should be "917ca2bb41787aadb5384038f2790b6e0a02e058593e37e1297f970be269e583" using other methods.. (ref:https://www.freeformatter.com/hmac-generator.html)
julia version v1.4.1, tried other strings and found the result incorrect..
@staticfloat

@staticfloat
Copy link
Member

The correct answer to this particular example is ce0006ef9b02c5c710b8bfcb47e6f5177b44323992e2918dfbdb087a03ec6f4f. The issue here is that you are not feeding tmp_key to the other tools you're checking against, you're feeding bytes2hex(tmp_key), they're not the same thing. The online tool that you posted is not interpreting the key as hex, it's reading the UTF-8 input bytes and using those binary representations.

If you want to do that, use hmac_sha256(collect(codeunits(tmp_key)), str) instead of hmac_sha256(tmp_key, str).

To double-check, use an online tool such as https://www.liavaag.org/English/SHA-Generator/HMAC/ and use Key type: HEX with the key e85726cc1b12609bbaebe535f0926f59.

@pankgeorg
Copy link

Nonetheless, this issue is the closest thing to hmac_sha256 documentation I've found. Thanks for the reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants