PHP to Ruby
Convert PHP code into Ruby!
-
sha1_file
Posted on May 11th, 2009 No commentsThe sha1_file() function calculates the sha1 hash of a file.
PHP
$my_file = '/home/ali/article.txt'; echo sha1_file($my_file); // => bef6b2b56f70eb6f2c250e00c855f4c0120832aa
Sha1 encryption can be done using the Digest::SHA1 class in Ruby, but to generate a hash for a file, we need to read it’s contents into a variable (string) first.
Ruby
require 'digest/sha1'; my_string = File.read('/home/ali/article.txt'); print Digest::SHA1.hexdigest(my_string); # => bef6b2b56f70eb6f2c250e00c855f4c0120832aa


