Module: GoPay::Crypt
Instance Method Summary collapse
- #bin2hex(bin) ⇒ Object
- #decrypt(encrypted_data, padding_off = false) ⇒ Object
- #encrypt(string) ⇒ Object
- #sha1(string) ⇒ Object
Instance Method Details
#bin2hex(bin) ⇒ Object
32 33 34 |
# File 'lib/gopay/crypt.rb', line 32 def bin2hex(bin) bin.scan(/../).map { |tuple| tuple.hex }.pack 'c*' end |
#decrypt(encrypted_data, padding_off = false) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/gopay/crypt.rb', line 22 def decrypt(encrypted_data, padding_off = false) encrypted_data = bin2hex(encrypted_data) des = OpenSSL::Cipher.new("des-ede3") des.decrypt des.padding = 0 if padding_off des.key = GoPay.configuration.secure_key result = "" result << des.update(encrypted_data) end |
#encrypt(string) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/gopay/crypt.rb', line 13 def encrypt(string) string = sha1(string) des = OpenSSL::Cipher::Cipher.new("des-ede3") des.encrypt des.key = GoPay.configuration.secure_key result = des.update(string) result.unpack("H*")[0] end |
#sha1(string) ⇒ Object
9 10 11 |
# File 'lib/gopay/crypt.rb', line 9 def sha1(string) Digest::SHA1.hexdigest(string) end |