Class: Hasher

Inherits:
Object
  • Object
show all
Defined in:
lib/Hasher-Generator.rb

Overview

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.

Instance Method Summary collapse

Instance Method Details

#md5_file(file_path) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# 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) ⇒ Object

MD5 METHODS



20
21
22
23
24
# 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) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# 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) ⇒ Object

SHA256 METHODS



40
41
42
43
44
45
# 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) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# 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) ⇒ Object

SHA512 METHODS



64
65
66
67
68
# 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