Sha256: 0f641887f880e52b75d89d93664a66dfa7b4329e9e9b653c294e7d2fdec813e5

Contents?: true

Size: 604 Bytes

Versions: 2

Compression:

Stored size: 604 Bytes

Contents

module Strongroom
  class Encryptor

    include HasRsaKey

    def initialize public_key, cipher = nil
      @cipher = cipher if cipher
      has_rsa_key public_key
    end

    def encrypt input
      key = cipher.random_key
      iv = cipher.random_iv

      cipher.encrypt
      cipher.key = key
      cipher.iv = iv

      Enigma.new \
        cipher: cipher.name,
        ciphertext: cipher.update(input) << cipher.final,
        encrypted_key: rsa_key.public_encrypt(key),
        iv: iv
    end

    private

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

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
strongroom-1.0.0 lib/strongroom/encryptor.rb
strongroom-0.0.2 lib/strongroom/encryptor.rb