Sha256: 3b5fcb2ab8d1f8154243d46dfbe7bb145bebb73e728466145057b854a8547e54

Contents?: true

Size: 677 Bytes

Versions: 1

Compression:

Stored size: 677 Bytes

Contents

require 'openssl'

module Fernet
  module Encryption
    AES_BLOCK_SIZE  = 16.freeze

    def self.encrypt(opts)
      cipher = OpenSSL::Cipher.new('AES-128-CBC')
      cipher.encrypt
      iv = opts[:iv] || cipher.random_iv
      cipher.iv  = iv
      cipher.key = opts[:key]
      [cipher.update(opts[:message]) + cipher.final, iv]
    end

    def self.decrypt(opts)
      decipher = OpenSSL::Cipher.new('AES-128-CBC')
      decipher.decrypt
      decipher.iv  = opts[:iv]
      decipher.key = opts[:key]
      decipher.update(opts[:ciphertext]) + decipher.final
    end

    def self.hmac_digest(key, blob)
      OpenSSL::HMAC.digest('sha256', key, blob)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fernet-2.0.rc1 lib/fernet/encryption.rb