MCPcopy Create free account
hub / github.com/Keeper-Security/Commander / decrypt_encryption_params

Function decrypt_encryption_params

keepercommander/utils.py:213–233  ·  view source on GitHub ↗
(encryption_params, password)

Source from the content-addressed store, hash-verified

211
212
213def decrypt_encryption_params(encryption_params, password): # type: (bytes, str) -> bytes
214
215 if len(encryption_params) != 100:
216 raise Exception('Invalid encryption params: bad params length')
217
218 _ = int.from_bytes(encryption_params[0:1], byteorder='big', signed=False)
219 iterations = int.from_bytes(encryption_params[1:4], byteorder='big', signed=False)
220 salt = encryption_params[4:20]
221 encrypted_data_key = encryption_params[20:]
222
223 key = crypto.derive_key_v1(password, salt, iterations)
224 decrypted_data_key = crypto.decrypt_aes_v1(encrypted_data_key, key, use_padding=False)
225
226 # validate the key is formatted correctly
227 if len(decrypted_data_key) != 64:
228 raise Exception('Invalid data key length')
229
230 if decrypted_data_key[:32] != decrypted_data_key[32:]:
231 raise Exception('Invalid data key: failed mirror verification')
232
233 return decrypted_data_key[:32]
234
235
236def create_encryption_params(password, salt, iterations, data_key): # type: (str, bytes, int, bytes) -> bytes

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected