Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jtdowney/cmac
Ruby implementation of the Cipher-based Message Authentication Code (CMAC)
https://github.com/jtdowney/cmac
Last synced: 3 months ago
JSON representation
Ruby implementation of the Cipher-based Message Authentication Code (CMAC)
- Host: GitHub
- URL: https://github.com/jtdowney/cmac
- Owner: jtdowney
- License: mit
- Created: 2012-11-23T13:38:42.000Z (about 12 years ago)
- Default Branch: main
- Last Pushed: 2020-06-16T01:49:36.000Z (over 4 years ago)
- Last Synced: 2024-03-14T22:24:26.331Z (10 months ago)
- Language: Ruby
- Homepage:
- Size: 15.6 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# CMAC [![Build Status](https://secure.travis-ci.org/jtdowney/cmac.png?branch=main)](https://travis-ci.org/jtdowney/cmac)
This gem is ruby implementation of the Cipher-based Message Authentication Code (CMAC) as defined in [RFC4493](http://tools.ietf.org/html/rfc4493), [RFC4494](http://tools.ietf.org/html/rfc4494), and [RFC4615](http://tools.ietf.org/html/rfc4615). Message authentication codes provide integrity protection of data given that two parties share a secret key.
```ruby
key = OpenSSL::Random.random_bytes(16)
message = 'attack at dawn'
cmac = CMAC.new(key)
cmac.sign(message)
=> "\xF6\xB8\xC1L]s\xBF\x1A\x87<\xA4\xA1Z\xE0f\xAA"
```Once you've obtained the signature (also called a tag) of a message you can use CMAC to verify it as well.
```ruby
tag = "\xF6\xB8\xC1L]s\xBF\x1A\x87<\xA4\xA1Z\xE0f\xAA"
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.
```ruby
key = 'setec astronomy'
message = 'attack at dawn'
cmac = CMAC.new(key)
cmac.sign(message)
=> "\\\x11\x90\xE6\x91\xB2\xC4\x82`\x90\xA6\xEC:\x0E\x1C\xF3"
```