# ruby-multihash [![](https://img.shields.io/badge/project-multiformats-blue.svg?style=flat-square)](https://github.com/multiformats/multiformats) [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](https://webchat.freenode.net/?channels=%23ipfs) [![](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) [![Travis CI](https://img.shields.io/travis/multiformats/ruby-multihash.svg?style=flat-square&branch=master)](https://travis-ci.org/multiformats/ruby-multihash) [![codecov.io](https://img.shields.io/codecov/c/github/multiformats/ruby-multihash.svg?style=flat-square&branch=master)](https://codecov.io/github/multiformats/ruby-multihash?branch=master) > A simple [Multihash](https://github.com/multiformats/multihash) implementation for ruby. A multihash is a digest with an embedded hash function code (and length) (['cause you never know](https://twitter.com/matthew_d_green/status/597409850381836288)). It was developed primarily for use with [IPFS](https://github.com/ipfs/ipfs), but is not specific to it. ## Install Add this line to your application's Gemfile: ```ruby gem 'multihashes' ``` And then execute: $ bundle Or install it yourself as: $ gem install multihashes ## Usage This is a low-level library. Bring your own digest. A binary digest goes in, a binary digest goes out. To compute a sha256 multihash that would work nicely with [IPFS](https://github.com/ipfs/ipfs): ```ruby require 'multihashes' require 'digest' digest = Digest::SHA256.digest 'Dade Murphy will never figure this one out' multihash_binary_string = Multihashes.encode digest, 'sha2-256' multihash_binary_string.unpack('H*').first # hex: "1220142711d38ca7a33c521841..." out = Multihashes.decode multihash_binary_string # => {:code=>18, :hash_function=>"sha2-256", :length=>32, :digest=>"\x14'\x11\xD3\x8C\xA7\xA3