onmyway133 / Arcane

:trident: CommonCrypto in Swift, and more
https://onmyway133.github.io/
Other
284 stars 22 forks source link

Expose digest type for HMAC generation #15

Closed basememara closed 6 years ago

basememara commented 6 years ago

I needed the base64 digest result of an HMAC encryption so I can generate JWT tokens (http://jwt.io), but Arcane was hard-coded to hex.

This PR exposes the option to choose hex or base64 digest for HMAC results:

HMAC.SHA256(string, key: key, digest: .hex) //Default
HMAC.SHA256(string, key: key, digest: .base64)

See how other languages natively expose this option and some online encryption results that returns both digests.

With this new DigestType enum, maybe you can delete Base64 and use this API instead:

Hash.SHA256(string, key: key, digest: .hex) //Default
Hash.SHA256(string, key: key, digest: .base64)

I hope this helps and makes sense. Thanks for a great library! 👍

onmyway133 commented 6 years ago

@basememara I totally accept this 👍 Thanks for the PR

onmyway133 commented 6 years ago

@basememara Hi, I bumped the version for you https://github.com/onmyway133/Arcane/releases/tag/1.2.1