È stato utile?

Soluzione

require 'digest/sha1'
Digest::SHA1.hexdigest 'foo'

Altri suggerimenti

Per un hash codificato Base64, per convalidare una firma OAuth, ho usato

require 'base64'
require 'hmac-sha1'

Base64.encode64((HMAC::SHA1.new('key') << 'base').digest).strip

Ho creato un aiutante gemma che è un semplice wrapper attorno al codice sha1

require 'rickshaw'
> Rickshaw::SHA1.hash('LICENSE.txt')

 => "4659d94e7082a65ca39e7b6725094f08a413250a" 

> "hello world".to_sha1

 => "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed" 

Dove "serialize" è una funzione utente definita altrove.

 def generateKey(data)
    return Digest::SHA1.hexdigest ("#{serialize(data)}")
 end
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top