Class: FastshopCatalog::Crypto

Inherits:
Object
  • Object
show all
Defined in:
lib/fastshop_catalog/crypto.rb

Instance Method Summary collapse

Constructor Details

#initialize(key = FastshopCatalog::Crypto.default_key, iv = FastshopCatalog::Crypto.default_iv) ⇒ Crypto

Returns a new instance of Crypto.



13
14
15
16
17
18
# 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

Instance Method Details

#encrypt(payload) ⇒ Object



20
21
22
23
# File 'lib/fastshop_catalog/crypto.rb', line 20

def encrypt(payload)
  encrypted = @cypher.update(payload) << @cypher.final
  Base64.strict_encode64(encrypted)
end