class FastshopCatalog::Crypto
Public Class Methods
new(key=FastshopCatalog::Crypto.default_key, iv=FastshopCatalog::Crypto.default_iv)
click to toggle source
# File lib/fastshop_catalog/crypto.rb, line 13 def initialize(key=FastshopCatalog::Crypto.default_key, iv=FastshopCatalog::Crypto.default_iv) @cypher = OpenSSL::Cipher::Cipher.new("AES-128-CBC") @cypher.encrypt @cypher.key = key @cypher.iv = iv end
Private Class Methods
default_iv()
click to toggle source
# File lib/fastshop_catalog/crypto.rb, line 31 def self.default_iv @@default_iv ||= FAST_IV.map{|x| x.chr}.join('') end
default_key()
click to toggle source
# File lib/fastshop_catalog/crypto.rb, line 35 def self.default_key @@default_key ||= hex_to_bin(DEFAULT_KEY) end
hex_to_bin(s)
click to toggle source
# File lib/fastshop_catalog/crypto.rb, line 27 def self.hex_to_bin(s) s.scan(/../).map { |x| x.hex.chr }.join end
Public Instance Methods
encrypt(payload)
click to toggle source
# File lib/fastshop_catalog/crypto.rb, line 20 def encrypt(payload) encrypted = @cypher.update(payload) << @cypher.final Base64.strict_encode64(encrypted) end