Class: Match::Encryption::EncryptionV1

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

Overview

This is to keep backwards compatibility with the old fastlane version which used the local openssl installation. The encryption parameters in this implementation reflect the old behavior which was the most common default value in those versions. As for decryption, 1.0.x OpenSSL and earlier versions use MD5, 1.1.0c and newer uses SHA256, we try both before giving an error

Constant Summary collapse

ALGORITHM =
'aes-256-cbc'

Instance Method Summary collapse

Instance Method Details

#decrypt(encrypted_data:, password:, salt:, hash_algorithm: "MD5") ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'match/lib/match/encryption/encryption.rb', line 24

def decrypt(encrypted_data:, password:, salt:, hash_algorithm: "MD5")
  cipher = ::OpenSSL::Cipher.new(ALGORITHM)
  cipher.decrypt

  keyivgen(cipher, password, salt, hash_algorithm)

  data = cipher.update(encrypted_data)
  data << cipher.final
end

#encrypt(data:, password:, salt:, hash_algorithm: "MD5") ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'match/lib/match/encryption/encryption.rb', line 13

def encrypt(data:, password:, salt:, hash_algorithm: "MD5")
  cipher = ::OpenSSL::Cipher.new(ALGORITHM)
  cipher.encrypt

  keyivgen(cipher, password, salt, hash_algorithm)

  encrypted_data = cipher.update(data)
  encrypted_data << cipher.final
  { encrypted_data: encrypted_data }
end