There is HashAlgorithm class in System.Security.Cryptography namespace which is stored into mscorlib, a core assembly of .NET Framework. So...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | Console = System::Console
ConsoleColor = System::ConsoleColor
BitConverter = System::BitConverter
HashAlgorithm = System::Security::Cryptography::HashAlgorithm
if ARGV.length != 0
begin
ARGV.each do |a|
#retrieve full path for input file(s)
item = File.expand_path(a)
#break if file(s) has null length
if File.lstat(item).size != 0
Console.foreground_color=ConsoleColor.Green
puts item
Console.reset_color
#available algorithms :)
['MD5', 'SHA1', 'SHA256', 'SHA384', 'SHA512', 'RIPEMD160'].each do |type|
#byte array
raw = HashAlgorithm.Create(type).ComputeHash(System::IO::File.ReadAllBytes(item))
#get hashes
puts BitConverter.ToString(raw).Replace('-', '').ToLower()
end
else
puts "File #{a} has null length."
end
end
rescue Exception => e
puts e.Message
end
else
puts "No one file has been specified."
end
|