Class: Strongroom::Encryptor

Inherits:
Object
  • Object
show all
Includes:
HasRsaKey
Defined in:
lib/strongroom/encryptor.rb

Instance Method Summary collapse

Constructor Details

#initialize(public_key, cipher = nil) ⇒ Encryptor

Returns a new instance of Encryptor.



6
7
8
9
# File 'lib/strongroom/encryptor.rb', line 6

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

Instance Method Details

#encrypt(input) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/strongroom/encryptor.rb', line 11

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