GOLF(2gg)
π 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's32bytes long, and for instance with SHA3-384 it's48bytes 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
- ubuntu questing: golf 601.4.41-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms