## Hash-based Message Authentication Codes [https://en.wikipedia.org/wiki/HMAC] In cryptography, an HMAC (sometimes expanded as either keyed-hash message authentication code or hash-based message authentication code) is a specific type of message authentication code (MAC) involving a cryptographic hash function and a secret cryptographic key. As with any MAC, it may be used to simultaneously verify both the data integrity and authenticity of a message. [C API Documentation](https://doc.libsodium.org/advanced/hmac-sha2) pgsodium provides hmacsha512 and hmacsha256, only 512-bit examples are provided below, the 256-bit API is identical but using names like `crypto_auth_hmacsha256_*`. ```python %load_ext sql ``` ```python %config SqlMagic.feedback=False %config SqlMagic.displaycon=False %sql postgresql://postgres@/ ``` ```sql %%sql CREATE EXTENSION IF NOT EXISTS pgsodium; ``` [] ### `crypto_auth_hmacsha512_keygen()` ```python key = %sql select pgsodium.crypto_auth_hmacsha512_keygen() key = key[0][0].tobytes() print(key) ``` b'|\'\x88\xf1\x88\x82\x8b\xcb"O\x1a\'\xb8#c\xa6f\x1ag\x05nx5\xc2\xe5u8