Class: Hasher

Inherits:
Object
  • Object
show all
Defined in:
lib/hasher.rb

Instance Method Summary collapse

Constructor Details

#initialize(method, pwd) ⇒ Hasher

Constructor method = “SHA1” or “MD5” pwd = Password



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/hasher.rb', line 26

def initialize(method, pwd)
        if (method.upcase == "SHA1")
                @hashfunc = Digest::SHA1.new
                @hashname = method.upcase
        elsif (method.upcase == "SHA256") 
          @hashfunc = Digest::SHA256.new
          @hashname = method.upcase
        elsif (method.upcase == "SHA384")
          @hashfunc = Digest::SHA384.new
          @hashname = method.upcase
        elsif (method.upcase == "SHA512")
          @hashfunc = Digest::SHA512.new
          @hashname = method.upcase
        else
          # default to MD5
                @hashfunc = Digest::MD5.new
                @hashname = "MD5"
        end
        @pwd = pwd
end

Instance Method Details

#hashnameObject



48
49
50
# File 'lib/hasher.rb', line 48

def hashname
	@hashname
end

#hashsumObject

Compute hash code



53
54
55
# File 'lib/hasher.rb', line 53

def hashsum
	return @hashfunc.hexdigest(@pwd)
end