Rimon S
Rimon S

Reputation: 1548

openssl ruby 1.9.3 and nodejs

In nodejs I can use crypto to do these function:

var equal = function(value, tag) {
var expected = crypto.createHash('sha1').update(value).digest('hex'),
  actual    = crypto.createHash('sha1').update(tag).digest('hex');
 return expected === actual;

}

How can I do the same using ruby 1.9.3 openssl library or any other library?

Upvotes: 1

Views: 79

Answers (1)

Paul Kehrer
Paul Kehrer

Reputation: 14089

You can do this with the OpenSSL bindings like this:

require 'openssl'
digest = OpenSSL::Digest::SHA1.new
hex_digest = digest.update("value").hexdigest

You can also use the digest/sha1 library (if you're on a Ruby runtime that doesn't support the OpenSSL bindings or you just don't want to use them)

require 'digest/sha1'
digest = Digest::SHA1.new
hex_digest = digest.update("value").hexdigest

Upvotes: 1

Related Questions