Module: JdPay::Des

Defined in:
lib/jd_pay/des.rb

Class Method Summary collapse

Class Method Details

.decrypt_3des(encrypt_str, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/jd_pay/des.rb', line 13

def decrypt_3des(encrypt_str, options = {})
  des2 = OpenSSL::Cipher::Cipher.new('des-ede3')
  des2.decrypt
  des2.key = decode_key(options)
  des2.iv = des2.random_iv
  des2.padding = 0
  result = (des2.update(to_decimal(encrypt_str)) + des2.final).bytes
  result.first(valid_size(result.shift(4))).map(&:chr).join.force_encoding('utf-8').encode('utf-8')
end

.encrypt_3des(str, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/jd_pay/des.rb', line 4

def encrypt_3des(str, options = {})
  des = OpenSSL::Cipher::Cipher.new('des-ede3')
  des.encrypt
  des.key = decode_key(options)
  des.iv = des.random_iv
  str = des.update(format_str_data(str))
  to_hex(str.bytes)
end