Sha256: 457c0b72a76c8d262ce4f91084b5083dfea1fd2f20e90423b751a3389314b6dc

Contents?: true

Size: 685 Bytes

Versions: 8

Compression:

Stored size: 685 Bytes

Contents

require 'openssl'

module Rmega
  module Crypto
    module Aes
      extend self

      def packing
        'l>*'
      end

      def cipher
        @cipher ||= OpenSSL::Cipher::AES.new(128, :CBC)
      end

      def encrypt(key, data)
        cipher.reset
        cipher.padding = 0
        cipher.encrypt
        cipher.key = key.pack(packing)
        result = cipher.update data.pack(packing)
        result.unpack packing
      end

      def decrypt(key, data)
        cipher.reset
        cipher.padding = 0
        cipher.decrypt
        cipher.key = key.pack packing
        result = cipher.update data.pack(packing)
        result.unpack packing
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rmega-0.1.7 lib/rmega/crypto/aes.rb
rmega-0.1.6 lib/rmega/crypto/aes.rb
rmega-0.1.5 lib/rmega/crypto/aes.rb
rmega-0.1.4 lib/rmega/crypto/aes.rb
rmega-0.1.3 lib/rmega/crypto/aes.rb
rmega-0.1.2 lib/rmega/crypto/aes.rb
rmega-0.1.1 lib/rmega/crypto/aes.rb
rmega-0.1.0 lib/rmega/crypto/aes.rb