Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jtdowney/hkdf
Rubygem for HMAC-based Key Derivation Function
https://github.com/jtdowney/hkdf
Last synced: 3 months ago
JSON representation
Rubygem for HMAC-based Key Derivation Function
- Host: GitHub
- URL: https://github.com/jtdowney/hkdf
- Owner: jtdowney
- License: mit
- Created: 2012-04-14T16:01:39.000Z (almost 13 years ago)
- Default Branch: main
- Last Pushed: 2021-04-27T15:36:27.000Z (over 3 years ago)
- Last Synced: 2024-09-19T21:07:08.254Z (4 months ago)
- Language: Ruby
- Homepage:
- Size: 43.9 KB
- Stars: 15
- Watchers: 4
- 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
# HKDF
[![CI](https://github.com/jtdowney/hkdf/actions/workflows/ci.yml/badge.svg)](https://github.com/jtdowney/hkdf/actions/workflows/ci.yml)
[![Gem Version](https://badge.fury.io/rb/hkdf.svg)](https://badge.fury.io/rb/hkdf)This is a ruby implementation of [RFC 5869](http://tools.ietf.org/html/rfc5869): HMAC-based Extract-and-Expand Key Derivation Function. The goal of HKDF is to take some source key material and generate suitable cryptographic keys from it.
## Usage
```ruby
hkdf = HKDF.new('source key material')
hkdf.read(32)
=> "\f#\xF4b\x98\x9B\x7Fw>|/|k\xF4k\xB7\xB9\x11e\xC5\x92\xD1\fH\xFDG\x94vt\xB4\x14\xCE"
```The default algorithm is HMAC-SHA256, you can override this and other defaults by providing an options hash during construction.
```ruby
hkdf = HKDF.new('source key material', :salt => 'NaCl', :algorithm => 'SHA1', :info => 'the 411')
hkdf.read(16)
=> "\xC0<\x13\x85\x8C\x84z\xCE\xC7\xCE+\xFF\x1C\xEB\xE6\xBC"
```You can also give an IO object as the source. It will be read in as a stream to generate the key. The optional argument `:read_size` can be used to control how many bytes are read from the IO at a time.
```ruby
hkdf = HKDF.new(File.new('/tmp/filename'), :read_size => 512)
hkdf.read(32)
=> "\f#\xF4b\x98\x9B\x7Fw>|/|k\xF4k\xB7\xB9\x11e\xC5\x92\xD1\fH\xFDG\x94vt\xB4\x14\xCE"
```## Requirements
- Ruby >= 2.4