cryptio package¶
Submodules¶
cryptio.header module¶
cryptio.io module¶
-
class
cryptio.io.
CryptIO
(_file, key)[source] Bases:
io.RawIOBase
CryptIO
is a minimal file-like object wrapper that only specifically implementsread()
,write()
, andclose()
.Example:
chunk = f.read(1024) f.write(b'bytes') f.close()
CryptIO
is also a context manager, and can be used with the with statement like a normalFileIO
object.The difference between
FileIO
andCryptIO
:read()
andwrite()
transparently handle aes-gcm decryption and encryption, respectively.close()
transparently handles message validation and file header updates- initialization vectors and gcm authentication tags are handled automatically
-
close
()[source] In addition to closing the underlying file object, also handle any outstanding encryptor or decryptor finalization as necessary.
Raises: InvalidTag – if the GCM tag does not match the ciphertext
-
read
(size=-1)[source] Read a ciphertext chunk from the underlying file object, and decrypt the result.
Parameters: size (int) – number of bytes to be read Returns: plaintext chunk Return type: bytes
-
write
(chunk)[source] Encrypts chunk, and writes the ciphertext to the underlying file object.
Parameters: chunk (bytes) – bytes or similar Returns: number of ciphertext bytes written Return type: int
-
cryptio.io.
default_cipher
(key, iv, tag=None)[source]
-
cryptio.io.
open
(file, mode='rb', *, key, _open=None, **kwargs)[source] open()
is a wrapper aroundio.open()
, with a few differences:- instead of some variant of an
io.FileIO
object, aCryptIO
wrapper is returned - only binary modes are supported
Example:
key = os.urandom(32) # 16 and 24-byte keys are also valid f = open('filename', 'rb', key=key)
For more information on how to manipulate the object returned by
open()
, seeCryptIO
Parameters: - file – path-like object; see open
- mode – mode string
- key – aes symmetric key
Returns: encrypted file object wrapper
Return type: - instead of some variant of an
Module contents¶
-
cryptio.
open
(file, mode='rb', *, key, _open=None, **kwargs)[source] open()
is a wrapper aroundio.open()
, with a few differences:- instead of some variant of an
io.FileIO
object, aCryptIO
wrapper is returned - only binary modes are supported
Example:
key = os.urandom(32) # 16 and 24-byte keys are also valid f = open('filename', 'rb', key=key)
For more information on how to manipulate the object returned by
open()
, seeCryptIO
Parameters: - file –
path-like object; see open
- mode – mode string
- key – aes symmetric key
Returns: encrypted file object wrapper
Return type: - instead of some variant of an