Class: String

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

Overview

Author:

  • Francesco Russo

Version:

  • 2.1.6

Instance Method Summary collapse

Instance Method Details

#hashsum(hash, salt = "") ⇒ Object

Encrypt a String with an algorithm and a salt if you want more security



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hashsum.rb', line 7

def hashsum(hash, salt = "")
  case hash
  when :md5
    Digest::MD5.hexdigest(salt+self)
  when :sha1
    Digest::SHA1.hexdigest(salt+self)
  when :sha2
    Digest::SHA2.hexdigest(salt+self)
  when :sha256
    Digest::SHA256.hexdigest(salt+self)
  when :sha384
    Digest::SHA384.hexdigest(salt+self)
  when :sha512
    Digest::SHA512.hexdigest(salt+self)
  else
    self # If there isn't an hashing algorithm the method return the string
  end
end

#to_md5(salt = "") ⇒ Object

Encrypt a String with MD5 and a salt if you want more security



26
27
28
# File 'lib/hashsum.rb', line 26

def to_md5(salt = "")
  hashsum(:md5, salt)
end

#to_sha1(salt = "") ⇒ Object

Encrypt a String with SHA1 and a salt if you want more security



30
31
32
# File 'lib/hashsum.rb', line 30

def to_sha1(salt = "")
  hashsum(:sha1, salt)
end

#to_sha2(salt = "") ⇒ Object

Encrypt a String with SHA2 and a salt if you want more security



34
35
36
# File 'lib/hashsum.rb', line 34

def to_sha2(salt = "")
  hashsum(:sha2, salt)
end

#to_sha256(salt = "") ⇒ Object

Encrypt a String with SHA256 and a salt if you want more security



38
39
40
# File 'lib/hashsum.rb', line 38

def to_sha256(salt = "")
  hashsum(:sha256, salt)
end

#to_sha384(salt = "") ⇒ Object

Encrypt a String with SHA384 and a salt if you want more security



42
43
44
# File 'lib/hashsum.rb', line 42

def to_sha384(salt = "")
  hashsum(:sha384, salt)
end

#to_sha512(salt = "") ⇒ Object

Encrypt a String with SHA512 and a salt if you want more security



46
47
48
# File 'lib/hashsum.rb', line 46

def to_sha512(salt = "")
  hashsum(:sha512, salt)
end