Class: Match::Encryption::MatchFileEncryption

Inherits:
Object
  • Object
show all
Defined in:
match/lib/match/encryption/encryption.rb

Overview

The methods of this class will encrypt or decrypt files in place, by default.

Instance Method Summary collapse

Instance Method Details

#decrypt(file_path:, password:, output_path: nil) ⇒ Object



145
146
147
148
149
150
151
# File 'match/lib/match/encryption/encryption.rb', line 145

def decrypt(file_path:, password:, output_path: nil)
  output_path = file_path unless output_path
  content = File.read(file_path)
  e = MatchDataEncryption.new
  decrypted_data = e.decrypt(base64encoded_encrypted: content, password: password)
  File.binwrite(output_path, decrypted_data)
end

#encrypt(file_path:, password:, output_path: nil, version: 2) ⇒ Object



137
138
139
140
141
142
143
# File 'match/lib/match/encryption/encryption.rb', line 137

def encrypt(file_path:, password:, output_path: nil, version: 2)
  output_path = file_path unless output_path
  data_to_encrypt = File.binread(file_path)
  e = MatchDataEncryption.new
  data = e.encrypt(data: data_to_encrypt, password: password, version: version)
  File.write(output_path, data)
end