API¶
This documents all interfaces of cryptio.
Open Interface¶
-
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
File Interface¶
-
class
cryptio.io.
CryptIO
(_file, key)[source]¶ 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