Crypto Implementation#
- samloader3.crypto.aes_decrypt(data: bytes, key: bytes) bytes [source]#
Decrypts data using AES encryption in CBC mode with PKCS7 padding.
- Parameters:
data – Encrypted data to be decrypted.
key – AES encryption key.
- Returns:
Decrypted data.
- samloader3.crypto.aes_encrypt(data: bytes, key: bytes) bytes [source]#
Encrypts data using AES encryption in CBC mode with PKCS7 padding.
- Parameters:
data – Data to be encrypted.
key – AES encryption key.
- Returns:
Encrypted data.
- samloader3.crypto.get_key(nonce: str) bytes [source]#
Generates an encryption key based on the provided nonce.
- Parameters:
nonce – Nonce used to generate the key.
- Returns:
Generated encryption key.
- samloader3.crypto.get_nonce(encrypted_nonce: str) str [source]#
Decrypts and retrieves the original nonce from the encrypted nonce.
- Parameters:
encrypted_nonce – Encrypted nonce.
- Returns:
Decrypted original nonce.
- samloader3.crypto.get_logic_check(data: str, nonce: str) str [source]#
Performs a logic check using the provided data and nonce.
- Parameters:
data – Data for the logic check.
nonce – Nonce used in the logic check.
- Returns:
Result of the logic check.
- samloader3.crypto.get_signature(nonce: str) str [source]#
Generates a signature for the provided nonce.
- Parameters:
nonce – Nonce for which the signature is generated.
- Returns:
Generated signature.
- samloader3.crypto.get_file_decryptor(key: bytes) CipherContext [source]#
Creates an AES decryption context for file decryption.
- Parameters:
key – AES decryption key.
- Returns:
AES decryption context.
- samloader3.crypto.unpad(data: bytes, block_size: int = 128) bytes [source]#
Removes PKCS7 padding from the data.
- Parameters:
data – Padded data.
block_size – Block size for PKCS7 padding.
- Returns:
Unpadded data.
- samloader3.crypto.pad(data: bytes, block_size: int = 128) bytes [source]#
Adds PKCS7 padding to the data.
- Parameters:
data – Data to be padded.
block_size – Block size for PKCS7 padding.
- Returns:
Padded data.
- samloader3.crypto.file_decrypt(path: str, out: str, key: bytes, block_size: int = 4096, key_version: str | None = None, cb: Callable[[], None] = None) None [source]#
Decrypts a file using a given key.
- Parameters:
path (str) – Path to the input encrypted file.
out (str) – Path to the output decrypted file.
key (bytes) – Encryption key.
block_size (int, optional) – Size of the encryption block, defaults to 4096.
key_version (t.Optional[str]) – Optional key version, defaults to None.
- Raises:
FileExistsError – Raised if the output path is the same as the input path.