Cmac
Crystal implementation of the Cipher-based Message Authentication Code (CMAC)
Install / Use
/learn @spider-gazelle/CmacREADME
Crystal Lang CMAC
Crystal implementation of the Cipher-based Message Authentication Code (CMAC) as defined in RFC4493, RFC4494, and RFC4615. Message authentication codes provide integrity protection of data given that two parties share a secret key.
key = Random.new.random_bytes(16)
message = "attack at dawn"
cmac = CMAC.new(key)
cmac.sign(message)
=> Bytes[246, 184, 193, 76, 93, 115, 191, 26, 135, 60, 164, 161, 90, 224, 102, 170]
Once you've obtained the signature (also called a tag) of a message you can use CMAC to verify it as well.
tag = Bytes[246, 184, 193, 76, 93, 115, 191, 26, 135, 60, 164, 161, 90, 224, 102, 170]
cmac.valid_message?(tag, message)
=> true
cmac.valid_message?(tag, "attack at dusk")
=> false
CMAC can also be used with a variable length input key as described in RFC4615.
key = "setec astronomy"
message = "attack at dawn"
cmac = CMAC.new(key)
cmac.sign(message)
=> Bytes[92, 17, 144, 230, 145, 178, 196, 130, 96, 144, 166, 236, 58, 14, 28, 243]
Related Skills
node-connect
347.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
