nuropb.encodings.encryption
Module Contents
Classes
Functions
Encrypt encoded payload with a key |
|
Decrypt encoded payload with a key |
|
Encrypt a symmetric key with an RSA public key |
|
Decrypt a symmetric key encrypted with an RSA private key |
API
- nuropb.encodings.encryption.encrypt_payload(payload: str | bytes, key: str | bytes) bytes
Encrypt encoded payload with a key
- Parameters:
payload – str | bytes
key – str
- Returns:
bytes
- nuropb.encodings.encryption.decrypt_payload(encrypted_payload: str | bytes, key: str | bytes) bytes
Decrypt encoded payload with a key
- Parameters:
encrypted_payload – str | bytes
key – str
- Returns:
bytes
- nuropb.encodings.encryption.encrypt_key(symmetric_key: bytes, public_key: cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey) bytes
Encrypt a symmetric key with an RSA public key
- Parameters:
symmetric_key – bytes
public_key – rsa.RSAPublicKey
- Returns:
bytes, encrypted symmetric key
- nuropb.encodings.encryption.decrypt_key(encrypted_symmetric_key: bytes, private_key: cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey) bytes
Decrypt a symmetric key encrypted with an RSA private key
- Parameters:
encrypted_symmetric_key – bytes
private_key – rsa.RSAPrivateKey
- Returns:
bytes, decrypted symmetric key
- class nuropb.encodings.encryption.Encryptor(service_name: Optional[str] = None, private_key: Optional[cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey] = None)
Initialization
- _service_name: str | None
None
- _private_key: cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey | None
None
- _service_public_keys: Dict[str, cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey]
None
- _correlation_id_symmetric_keys: Dict[str, bytes]
None
- classmethod new_symmetric_key() bytes
Generate a new symmetric key
- Returns:
bytes
- add_public_key(service_name: str, public_key: cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey) None
Add a public key for a service
- Parameters:
service_name – str
public_key – rsa.RSAPublicKey
- get_public_key(service_name: str) cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey | None
Get a public key for a service
- Parameters:
service_name – str
- Returns:
rsa.RSAPublicKey
- has_public_key(service_name: str) bool
Check if a service has a public key
- Parameters:
service_name – str
- Returns:
bool
- encrypt_payload(payload: bytes, correlation_id: str, service_name: Optional[str | None] = None) bytes
Encrypt a payload with a symmetric key
Modes:
Sending a payload to a service (Encrypt)
Sending a response payload from a service (Encrypt)
- Parameters:
payload –
correlation_id –
service_name –
- Returns:
bytes
- decrypt_payload(payload: bytes, correlation_id: str) bytes
Encrypt a payload with a symmetric key
Modes: 2. Receiving a response payload from a service (Decrypt) 3. Receiving a rpc payload (Decrypt)
- Parameters:
payload –
correlation_id –
- Returns: