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

Function encrypt_for_team

keepercommander/nested_share_folder/common.py:214–240  ·  view source on GitHub ↗

Encrypt *plaintext_key* using the best available team key.

(plaintext_key: bytes, team_keys,
                     prefer_aes: bool = False,
                     forbid_rsa: bool = False)

Source from the content-addressed store, hash-verified

212
213
214def encrypt_for_team(plaintext_key: bytes, team_keys,
215 prefer_aes: bool = False,
216 forbid_rsa: bool = False) -> Tuple[bytes, int]:
217 """Encrypt *plaintext_key* using the best available team key.
218 """
219 aes = getattr(team_keys, 'aes', None)
220 ec_bytes = getattr(team_keys, 'ec', None)
221 rsa_bytes = getattr(team_keys, 'rsa', None)
222
223 if prefer_aes and aes:
224 if forbid_rsa:
225 return (crypto.encrypt_aes_v2(plaintext_key, aes),
226 folder_pb2.encrypted_by_data_key_gcm)
227 return (crypto.encrypt_aes_v1(plaintext_key, aes),
228 folder_pb2.encrypted_by_data_key)
229
230 if rsa_bytes and not forbid_rsa:
231 rsa_key = crypto.load_rsa_public_key(rsa_bytes)
232 return (crypto.encrypt_rsa(plaintext_key, rsa_key),
233 folder_pb2.encrypted_by_public_key)
234
235 if ec_bytes:
236 ec_key = crypto.load_ec_public_key(ec_bytes)
237 return (crypto.encrypt_ec(plaintext_key, ec_key),
238 folder_pb2.encrypted_by_public_key_ecc)
239
240 raise ValueError("No public key found for team")
241
242
243def resolve_uid_email(params, user_identifier: str) -> Tuple[Optional[bytes], str]:

Callers 2

grant_folder_access_v3Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected