Sha256: 6efd64133c091d14c01a55edb56e7ff9427836a0accee1dc43bfb41b340d5b28

Contents?: true

Size: 608 Bytes

Versions: 3

Compression:

Stored size: 608 Bytes

Contents

module Strongroom
  class Decryptor

    include HasRsaKey

    def initialize private_key, cipher_locator = nil
      @cipher_locator = cipher_locator || CipherLocator.new
      has_rsa_key private_key
    end

    def decrypt enigma
      cipher = @cipher_locator.for(enigma)
      cipher.decrypt
      cipher.key = rsa_key.private_decrypt enigma.encrypted_key
      cipher.iv = enigma.iv
      cipher.update(enigma.ciphertext) << cipher.final
    end

    private
    attr_reader :cipher

    class CipherLocator
      def for enigma
        OpenSSL::Cipher.new enigma.cipher
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
strongroom-1.0.0 lib/strongroom/decryptor.rb
strongroom-0.0.2 lib/strongroom/decryptor.rb
strongroom-0.0.1 lib/strongroom/decryptor.rb