Sha256: cb93b93e127d164674f06143f197b46acef08b3d37bff58a43f2f64d1ae023d7

Contents?: true

Size: 697 Bytes

Versions: 1

Compression:

Stored size: 697 Bytes

Contents

module Passkit
  class UrlEncrypt
    class << self
      def encrypt(payload)
        string = payload.to_json
        cipher = cypher.encrypt
        cipher.key = encryption_key
        s = cipher.update(string) + cipher.final

        s.unpack1('H*').upcase
      end

      def decrypt(string)
        cipher = cypher.decrypt
        cipher.key = encryption_key
        s = [string].pack('H*').unpack('C*').pack('c*')

        JSON.parse(cipher.update(s) + cipher.final, symbolize_names: true)
      end

      private

      def encryption_key
        Rails.application.secret_key_base[0..15]
      end

      def cypher
        OpenSSL::Cipher.new('AES-128-CBC')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
passkit-0.1.0 lib/passkit/url_encrypt.rb