0

How to get hex of string in SHA-0 in ruby >=1.9.3?

I searched on GitHub and here, I looked at the module Digest, but couldn't find an answer.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
Artem D
  • 3
  • 2

1 Answers1

0

There are lot of crypto methods in the OpenSSL module, including SHA. (SHA was later named SHA0)

http://ruby-doc.org/stdlib-1.9.3/libdoc/openssl/rdoc/OpenSSL/Digest.html

require 'openssl'
digest_maker = OpenSSL::Digest::SHA.new
digest = digest_maker.digest( 'your_message_here' )

You can convert the digest to hex with unpack:

hex_digest = digest.unpack('H*')
hex_digest[0]   # because array is returned by unpack
Meier
  • 3,858
  • 1
  • 17
  • 46