API Documentation
package
cryptocfb
A Python module to encrypt and decrypt data with AES-128 CFB mode.
- Author: Quan Lin
- License: MIT
Classes
CryptoCFB— A class to encrypt and decrypt data with AES-128 CFB mode.
class
cryptocfb.CryptoCFB(key, iv, bits=128)
A class to encrypt and decrypt data with AES-128 CFB mode.
Parameters
key(bytes) — The key for AES-128 CFB mode. It must be 16 bytes.iv(bytes) — The initialization vector for AES-128 CFB mode. It must be 16 bytes.bits(int, optional) — CFB mode, supported CFB modes : 8/64/128-bit CFB mode. (default is128)
Attributes
crypt_inplace(buf, is_encrypt=True)— Encrypt or decrypt buf inplace.decrypt(cipher)— Decrypt cipher data.encrypt(plain)— Encrypt plain data.next_vector(bytes) — The next vector for encryption or decryption.reset_vector()— Reset next_vector.
Notes
This class can encrypt or decrypt large data part by part. Except for the last part, every part must be multiple of (bits // 8) bytes. It can do encryption and decryption inplace to reduce memory footprint.
Methods
crypt_inplace(buf,is_encrypt)(bytearray) — Encrypt or decrypt buf inplace.decrypt(cipher)(bytearray) — Decrypt cipher data.encrypt(plain)(bytearray) — Encrypt plain data.reset_vector()— Reset next_vector.
method
reset_vector()Reset next_vector.
Reset next_vector before re-use.
method
crypt_inplace(buf, is_encrypt=True)Encrypt or decrypt buf inplace.
Parameters
buf(bytearray) — The buffer to encrypt or decrypt. It can be the whole data or a part of the data. If not the last part of the data, len(buf) must be multiple of (bits // 8).is_encrypt(bool, optional) — True for encryption or False for decryption. (default isTrue)
Returns (bytearray)
The original buffer.
method
encrypt(plain)Encrypt plain data.
Parameters
plain(bytes or bytearray) — The plain data to encrypt.
Returns (bytearray)
The encrypted data.
method
decrypt(cipher)Decrypt cipher data.
Parameters
cipher(bytes or bytearray) — The cipher data to decrypt.
Returns (bytearray)
The decrypted data.