class Match::Encryption::MatchDataEncryption
Constants
- V1_PREFIX
- V2_PREFIX
Public Instance Methods
Source
# File match/lib/match/encryption/encryption.rb, line 108 def decrypt(base64encoded_encrypted:, password:) stored_data = Base64.decode64(base64encoded_encrypted) if stored_data.start_with?(V2_PREFIX) salt = stored_data[20..27] auth_tag = stored_data[28..43] data_to_decrypt = stored_data[44..-1] e = EncryptionV2.new e.decrypt(encrypted_data: data_to_decrypt, password: password, salt: salt, auth_tag: auth_tag) else salt = stored_data[8..15] data_to_decrypt = stored_data[16..-1] e = EncryptionV1.new begin # Note that we are not guaranteed to catch the decryption errors here if the password or the hash is wrong # as there's no integrity checks. # see https://github.com/fastlane/fastlane/issues/21663 e.decrypt(encrypted_data: data_to_decrypt, password: password, salt: salt) # With the wrong hash_algorithm, there's here 0.4% chance that the decryption failure will go undetected rescue => _ex # With a wrong password, there's a 0.4% chance it will decrypt garbage and not fail fallback_hash_algorithm = "SHA256" e.decrypt(encrypted_data: data_to_decrypt, password: password, salt: salt, hash_algorithm: fallback_hash_algorithm) end end end
Source
# File match/lib/match/encryption/encryption.rb, line 94 def encrypt(data:, password:, version: 2) salt = SecureRandom.random_bytes(8) if version == 2 e = EncryptionV2.new encryption = e.encrypt(data: data, password: password, salt: salt) encrypted_data = V2_PREFIX + salt + encryption[:auth_tag] + encryption[:encrypted_data] else e = EncryptionV1.new encryption = e.encrypt(data: data, password: password, salt: salt) encrypted_data = V1_PREFIX + salt + encryption[:encrypted_data] end Base64.encode64(encrypted_data) end