Module: JytPay::Encrypt::Des

Defined in:
lib/jyt_pay/encrypt/des.rb

Constant Summary

ALG =
'DES-CBC'

Class Method Summary collapse

Class Method Details

.decrypt(xml_enc, key_str) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/jyt_pay/encrypt/des.rb', line 18

def self.decrypt(xml_enc, key_str)
  xml_str = [xml_enc].pack 'H*'

  des = OpenSSL::Cipher::Cipher.new(ALG)
  des.decrypt
  des.key = key_str
  des.iv = key_str
  des.update(xml_str) + des.final
end

.encrypt(str, key_arg = Encrypt::DES_KEY) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/jyt_pay/encrypt/des.rb', line 9

def self.encrypt(str, key_arg = Encrypt::DES_KEY)
  des = OpenSSL::Cipher::Cipher.new(ALG)
  des.key = key_arg
  des.iv = key_arg
  des.encrypt
  cipher = des.update(str) + des.final
  cipher.unpack('H*')[0]
end