class Hasher
HASHER CLASS FOR MD5 AND SHA256/512 HASHES
Examples:
hasher = Hasher.new puts hasher.md5_string("Example string here") file_hash = Hasher.new puts file_hash.md5_file("/home/username/Desktop/testfile.txt")
The same string and file methods can be called with other algorithms such as sha256_string
and sha256_file
and sha512_string
and sha512_file
Have fun! and sorry for Versions 0.0.0-0.0.1 bad examples , they didnt work. These examples are up to date and work as expected - GR33N-H4Z3.
Public Instance Methods
md5_file(file_path)
click to toggle source
# File lib/Hasher-Generator.rb, line 26 def md5_file(file_path) if file_path.nil? then puts '[!]Invalid file or path!' exit 1 else md5 = Digest::MD5.file file_path # returns md5 hash of the file return md5 end end
md5_string(string)
click to toggle source
MD5 METHODS
# File lib/Hasher-Generator.rb, line 20 def md5_string(string) md5 = Digest::MD5.new # returns md5 hash of the string return md5.hexdigest string end
sha256_file(file_path)
click to toggle source
# File lib/Hasher-Generator.rb, line 47 def sha256_file(file_path) if file_path.nil? then puts '[!]Invalid file or path!' exit 1 else sha256 = Digest::SHA256.file file_path # returns SHA256 hash of file return sha256 end end
sha256_string(string)
click to toggle source
SHA256 METHODS
# File lib/Hasher-Generator.rb, line 40 def sha256_string(string) sha256 = Digest::SHA256.new # returns SHA256 hash of string return sha256.hexdigest string end
sha512_file(file_path)
click to toggle source
# File lib/Hasher-Generator.rb, line 71 def sha512_file(file_path) if file_path.nil? then puts '[!]Invalid file or path!' exit 1 else sha512 = Digest::SHA512.file file_path # returns SHA512 hash of file return sha512 end end
sha512_string(string)
click to toggle source
SHA512 METHODS
# File lib/Hasher-Generator.rb, line 64 def sha512_string(string) sha512 = Digest::SHA512.new # returns SHA512 hash of string return sha512.hexdigest string end