Sha256: a023ab58decf0cfbf36d64105ea3060ce1bc415e4bceebb9fd81e7642f430249

Contents?: true

Size: 1008 Bytes

Versions: 8

Compression:

Stored size: 1008 Bytes

Contents

module FastshopCatalog

  require 'openssl'
  require 'base64'
  
  #if the iv changes, you can reconfigure it here
  FAST_IV = [0xf, 0x6f, 0x13, 0x2e, 0x35, 0xc2, 0xcd, 0xf9, 0x5, 0x46, 0x9c, 0xea, 0xa8, 0x4b, 0x73, 0xcc]
  #if this key changes, check the readme for instructions
  DEFAULT_KEY = 'D027CF4E32A9A69363DB9D72234F97B4'
  
  class Crypto
    
    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

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

    def self.hex_to_bin(s) 
      s.scan(/../).map { |x| x.hex.chr }.join
    end

    def self.default_iv
      @@default_iv ||= FAST_IV.map{|x| x.chr}.join('')
    end
    
    def self.default_key
      @@default_key ||= hex_to_bin(DEFAULT_KEY)
    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fastshop_catalog-0.0.8 lib/fastshop_catalog/crypto.rb
fastshop_catalog-0.0.7 lib/fastshop_catalog/crypto.rb
fastshop_catalog-0.0.6 lib/fastshop_catalog/crypto.rb
fastshop_catalog-0.0.5 lib/fastshop_catalog/crypto.rb
fastshop_catalog-0.0.4 lib/fastshop_catalog/crypto.rb
fastshop_catalog-0.0.3 lib/fastshop_catalog/crypto.rb
fastshop_catalog-0.0.2 lib/fastshop_catalog/crypto.rb
fastshop_catalog-0.0.1 lib/fastshop_catalog/crypto.rb