Class: MobileSecrets::FileHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/src/file_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(password) ⇒ FileHandler

Returns a new instance of FileHandler.



6
7
8
# File 'lib/src/file_handler.rb', line 6

def initialize password
  @password = password
end

Instance Method Details

#encrypt(file) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/src/file_handler.rb', line 10

def encrypt file
  file_content = File.read file
  cipher = OpenSSL::Cipher::AES256.new :CBC
  cipher.encrypt
  iv = cipher.random_iv
  cipher.key = @password
  cipher_text = iv + cipher.update(file_content) + cipher.final
  cipher_text
end