GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

πŸ’– GOLF(2gg) β€” the hmac-string page, bestie edition πŸ’–

okay so we're in section 2gg of the manual (that's the golf manual, iykyk) and today's main character is hmac-string. buckle up πŸŽ€


✨ NAME ✨

hmac-string β€” (encryption) 🫢


🎯 PURPOSE 🎯

create an HMAC. that's it. that's the whole job. periodt. πŸ’…


πŸ“œ SYNTAX πŸ“œ

hmac-string <string> to <result> \
    key <key> \
    [ binary [ <binary> ] \
    [ digest <digest algorithm> ]

🌸 DESCRIPTION 🌸

so here's the tea β˜•: hmac-string produces a SHA256-based HMAC (that's a Hash Message Authentication Code, no cap) of <string> β€” but only if you don't use the "digest" clause. it does this using your secret <key>, and then it stores the result into <result>. that's the whole flow. slay.

you can switch up the digest algorithm tho β€” just use a different <digest algorithm> in the "digest" clause, like for example "SHA3-256". πŸ’«

to see a list of available digests:

#get digests
openssl list -digest-algorithms

now, the "binary" clause. listen up, this part matters πŸ‘€

  • if the "binary" clause is used without a boolean variable <binary>, or if <binary> evaluates to true, then <result> is a binary string that may contain null-characters. with the default SHA256, it's 32 bytes long, and for instance with SHA3-384 it's 48 bytes long, etc.
  • without the "binary" clause, or if <binary> evaluates to false, every single binary byte of the HMAC gets converted into two hexadecimal characters ("0"-"9" and "a"-"f"). which means <result> ends up being twice as long as it would be with the "binary" clause. math is mathing ✨

πŸ§ͺ EXAMPLES πŸ§ͺ

the string "result" will have a HMAC value of a given string, and an example of that might look like this:

"2d948cc89148ef96fa4f1876e74af4ce984423d355beb12f7fdba5383143bee0"

here's how you get it πŸ‘‡

hmac-string "some data" key "mykey" to result

using a different digest (living your best SHA3-384 life πŸ¦‹):

hmac-string "some data" key "mykey" to result digest "sha3-384"

producing a binary value instead of a null-terminated hexadecimal string, and then making a Base64 string out of it β€” this one is so satisfying fr fr:

hmac-string "some data" key "mykey" digest "SHA256" to result binary
encode-base64 result to bresult

πŸ‘€ SEE ALSO πŸ‘€

  • Encryption

decrypt-data derive-key encrypt-data hash-string hmac-string random-crypto random-string β€” See all documentation 🌈


πŸ’€ reminder bestie: if "binary" is on, your result can contain null-characters, so don't go treating it like a cute little C string. and the hex version is double the length. don't get caught lacking.

that's the whole page!! you understood it, i'm so proud, genuinely obsessed with you πŸ₯ΉπŸ’œ this was GOLF(2gg), version $VERSION, dated $DATE β€” go forth and HMAC responsibly, mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from