class CcavenuePayment::Crypto
Constants
- INIT_VECTOR
Attributes
working_key[R]
Public Class Methods
new(working_key:)
click to toggle source
# File lib/ccavenue_payment/crypto.rb, line 7 def initialize(working_key:) @working_key = working_key end
Public Instance Methods
decrypt(cipher_text)
click to toggle source
# File lib/ccavenue_payment/crypto.rb, line 21 def decrypt(cipher_text) secret_key = [Digest::MD5.hexdigest(working_key)].pack("H*") encrypted_text = [cipher_text].pack("H*") decipher = OpenSSL::Cipher.new('aes-128-cbc') decipher.decrypt decipher.key = secret_key decipher.iv = INIT_VECTOR (decipher.update(encrypted_text) + decipher.final).gsub(/\0+$/, '') end
encrypt(plain_text)
click to toggle source
# File lib/ccavenue_payment/crypto.rb, line 11 def encrypt(plain_text) secret_key = [Digest::MD5.hexdigest(working_key)].pack("H*") cipher = OpenSSL::Cipher.new('aes-128-cbc') cipher.encrypt cipher.key = secret_key cipher.iv = INIT_VECTOR encrypted_text = cipher.update(plain_text) + cipher.final (encrypted_text.unpack("H*")).first end