Jak utworzyć hash SHA1 w ruby?

 152
Author: quackingduck, 2008-08-29

4 answers

require 'digest/sha1'
Digest::SHA1.hexdigest 'foo'
 369
Author: devstopfix,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-08-29 15:56:48

Dla zakodowanego hasha Base64, aby zwalidować podpis Oauth, użyłem

require 'base64'
require 'hmac-sha1'

Base64.encode64((HMAC::SHA1.new('key') << 'base').digest).strip
 8
Author: Thiago Ganzarolli,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-05-11 20:42:30

Stworzyłem helper gem który jest prostym opakowaniem wokół jakiegoś kodu sha1

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

 => "4659d94e7082a65ca39e7b6725094f08a413250a" 

> "hello world".to_sha1

 => "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed" 
 6
Author: Gregory Ostermayr,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-11-06 17:51:39

Gdzie 'serialize' to jakaś funkcja użytkownika zdefiniowana gdzie indziej.

 def generateKey(data)
    return Digest::SHA1.hexdigest ("#{serialize(data)}")
 end
 -25
Author: r4ccoon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-03-26 05:12:04