CipherStream class¶
- class crsysapi.CipherStream¶
Stream cipher functions.
- class Alg¶
Stream cipher algorithm.
- ARCFOUR = 1¶
ARCFOUR (RC4) algorithm
- CHACHA20 = 3¶
Chacha20 algorithm
- SALSA20 = 2¶
Salsa20 algorithm
- static bytes(data, key, iv, alg, counter=0)¶
Encipher data in array of bytes using specified stream cipher.
- Parameters:
data (bytes) -- Input data to be encrypted.
key (bytes) -- Key (length restrictions apply, see Remarks).
iv (bytes) -- Initialization Vector (IV, nonce) or None for Arcfour.
alg (CipherStream.Alg) -- Stream cipher algorithm.
counter (int) -- Counter value for ChaCha20 only, otherwise ignored.
- Returns:
Ciphertext in a byte array.
- Return type:
bytes
Note
Arcfour: any length key; no IV.
Salsa20: key must be exactly 16 or 32 bytes and IV exactly 8 bytes long.
ChaCha20: key must be exactly 16 or 32 bytes and IV exactly 8, 12, or 16 bytes long. Counter is ignored if IV is 16 bytes.
- static file(fileout, filein, key, iv, alg, counter=0)¶
Encipher data in a file using specified stream cipher.
- Parameters:
fileout (str) -- Name of output file to be created or overwritten.
filein (str) -- Name of input file
key (bytes) -- Key (length restrictions apply, see Remarks).
iv (bytes) -- Initialization Vector (IV, nonce) or None for Arcfour.
alg (CipherStream.Alg) -- Stream cipher algorithm.
counter (int) -- Counter value for ChaCha20 only, otherwise ignored.
- Returns:
0 if successful.
- Return type:
int
Note
Arcfour: any length key; no IV.
Salsa20: key must be exactly 16 or 32 bytes and IV exactly 8 bytes long.
ChaCha20: key must be exactly 16 or 32 bytes and IV exactly 8, 12, or 16 bytes long. Counter is ignored if IV is 16 bytes.