AES Stream Cipher with CFB and OpenPGP Modes
Project description
Sandra
Sandra implements CFB and OpenPGP-CFB built on top of pycryptodome.
Usage
Loading Data
Sandra.load_data(
path # str -> path to data to be loaded
)
Writing Data
Sandra.write_data(
file_names, # name of files to be written
file_data, # data to be written, must be the same length as file_names
path='.' # path to write data to
)
Examples
RSA File Encryption
import Sandra
file_names, file_data = Sandra.load_data('./taylor_txt/taylor_swift_1KB.txt')
enc_dec_rsa = Sandra.RSA(256)
ciphertext = enc_dec_rsa.encrypt(file_data[0])
print(len(ciphertext))
plaintext = enc_dec_rsa.decrypt(ciphertext)
print(plaintext == file_data[0])
Sandra.write_data(
file_names, # name of file to be written
[plaintext], # data to be written, must be same length as file_names
path='./taylor_txt_ed' # path to write data to
)
AES CFB Mode Sample(NIST) Encryption
import Sandra
#Test Case from http://csrc.nist.gov/groups/STM/cavp/block-ciphers.html#aes
data = bytes.fromhex('fffffe00000000000000000000000000')
iv = bytes.fromhex('fffffe00000000000000000000000000')
key = bytes.fromhex('00000000000000000000000000000000')
enc_dec_sandra = Sandra.AES(key, Sandra.MODE_CFB, iv, segment_size=16)
ciphertext = enc_dec_sandra.encrypt(data)
plaintext = enc_dec_sandra.decrypt(ciphertext)
AES CFB Mode File Encryption
import Sandra
iv = bytes.fromhex('fffffe00000000000000000000000000')
key = bytes.fromhex('00000000000000000000000000000000')
file_names, file_data = Sandra.load_data('./taylor_txt/taylor_swift_1KB.txt')
enc_dec_cfb = Sandra.AES(key, Sandra.MODE_CFB, iv, segment_size=16)
ciphertext = enc_dec_cfb.encrypt(file_data[0])
print(len(ciphertext))
plaintext = enc_dec_cfb.decrypt(ciphertext)
print(plaintext == file_data[0])
Sandra.write_data(
file_names, # name of file to be written
[plaintext], # data to be written, must be same length as file_names
path='./taylor_txt_ed' # path to write data to
)
AES OpenPGP-CFB Mode File Encryption
In This mode, the first 18 bytes of cipher text contain the encrypted IV
Padding here is unnecessary as this mode is a stream cipher
import Sandra
iv = bytes.fromhex('fffffe00000000000000000000000000')
key = bytes.fromhex('00000000000000000000000000000000')
file_names, file_data = Sandra.load_data('./taylor_txt/taylor_swift_1KB.txt')
print(len(file_data[0]))
file_data_padded = Sandra.pad(file_data, Sandra.AES_BLOCK_SIZE)
print(len(file_data_padded[0]))
enc_dec_pgp = Sandra.AES(key, Sandra.MODE_OPENPGP, iv)
ciphertext = enc_dec_pgp.encrypt(file_data_padded[0])
eiv, ciphertext = ciphertext[:18], ciphertext[18:]
print(len(ciphertext))
plaintext = enc_dec_pgp.decrypt(ciphertext)
print(len(plaintext))
plaintext = Sandra.unpad(plaintext,Sandra.AES_BLOCK_SIZE)
print(len(plaintext))
print(plaintext == file_data[0])
Sandra.write_data(
file_names, # name of file to be written
[plaintext], # data to be written, must be same length as file_names
path='./taylor_txt_ed' # path to write data to
)
Performance
To obtain a table like this one, run
import Sandra
file_names, file_data = Sandra.load_data('path/to/data')
Sandra.performance_test(file_names, file_data)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Sandra-0.0.17.tar.gz
(6.9 kB
view hashes)