Crypto
sereto.crypto
¶
DerivedKeyResult
¶
Bases: NamedTuple
Result of the Argon2 key derivation function.
Source code in sereto/crypto.py
22 23 24 25 26 |
|
decrypt_file(file, keep_original=True)
¶
Decrypts a .sereto file using AES-GCM encryption and saves it with a .tgz suffix.
This function retrieves a password from the system keyring, derives an encryption key using Argon2, parses the
header (contains nonce and seed), and decrypts the file content. The decrypted data is then saved with a .tgz
suffix and the original file is deleted (use keep_original=True
to overwrite deletion).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
FilePath
|
The path to the encrypted .sereto file. |
required |
keep_original
|
bool
|
If True, the original encrypted file is kept. Defaults to False. |
True
|
Raises:
Type | Description |
---|---|
Abort
|
If the file size exceeds 1 GiB and the user chooses not to continue. |
SeretoValueError
|
If the file is corrupted or not encrypted with SeReTo. |
Returns:
Type | Description |
---|---|
Path
|
Path to the decrypted file. |
Source code in sereto/crypto.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
derive_key_argon2(password, salt=None, memory_cost=1048576, time_cost=4, parallelism=8)
¶
Derive a key using Argon2id from a password.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
password
|
TypePassword
|
Password to derive the key from. |
required |
salt
|
TypeSalt16B | None
|
16 bytes long salt. If None, a random salt is generated. |
None
|
memory_cost
|
int
|
Memory cost in KiB. Defaults to 1 GiB. |
1048576
|
time_cost
|
int
|
Time cost (number of iterations). Defaults to 4. |
4
|
parallelism
|
int
|
Parallelism factor. Defaults to 8. |
8
|
Returns:
Type | Description |
---|---|
DerivedKeyResult
|
Derived key and salt. |
Source code in sereto/crypto.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
encrypt_file(file, keep_original=False)
¶
Encrypts a given file using AES-GCM encryption and saves it with a .sereto suffix.
This function retrieves a password from the system keyring, derives an encryption key using Argon2, and encrypts
the file content. The encrypted data is then saved with a specific header and the original file is deleted (use
keep_original=True
to overwrite deletion).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
FilePath
|
The path to the file to be encrypted. |
required |
keep_original
|
bool
|
If True, the original encrypted file is kept. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Path
|
Path to the encrypted file with suffix |
Raises:
Type | Description |
---|---|
SeretoEncryptionError
|
If the password is not found in the system keyring. |
SeretoPathError
|
If the provided file does not exist. |
SeretoValueError
|
If the file size exceeds 1 GiB and the user chooses not to continue. |
Source code in sereto/crypto.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|