Assignment 2 Encrypt and decrpyt messages using symmetric (AES) and asymmetric (RSA) cryptosystems. Use digital signatures to verify the integrity of messages. Description: Use Python 3.7+ and the PyCryptodome library to implement symmetric and asymmetric encryption and digital signature verification. Your task is to implement the classes/functions outlined in the provided skeleton code. You should not need any other imports or 3rd-party libraries. The file also contains testing code that you can use to validate whether you have correctly used the encryption/decryption algorithms. For more information about the PyCryptodome library, visit the documentation. In addition to using AES for symmetric encryption and RSA for asymmetric encryption, you will implement a hybrid cryptosystem that combines these two algorithms. A hybrid cryptosystem allows us to efficiently use public-key encryption with large amounts of data since RSA can only encrypt data smaller than the key length. In this scheme, the data is encrypted using a symmetric algorithm and the corresponding symmetric key is encrypted using the asymmetric algorithm. The examples section of the PyCryptodome library documentation is a good starting point for understanding how to use to the cryptographic primitives to implement encryption/decryption. Implementation Notes: For AES encryption, use CBC mode and ensure you handle the block size (padding) and initialization vector requirements of this algorithm. In the various encryption/signature classes, you will store the AES/RSA key or RSAEncryption object and create the corresponding cipher as needed. The cipher objects provided by the PyCryptodome library are stateful. For the to file method of RSAEncryption, use pkcs=8 and protection=”scryptAndAES128-CBC” when saving a private key. Use the default parameters for a public key. As mentioned in the documentation, use PKCS1 OAEP for encryption using RSA and pkcs1 15 for signing using RSA. Use SHA256 as the hash function to calculate the digests for the digital signatures. For padding and unpadding data, use the functions provided by the Crypto.Util.Padding module instead of implementing your own. Use the named constants defined by the PyCrytodome library. For example, for the AES block size, use Crypto.Cipher.AES.block size instead of 16 directly. Do not change the class/function names given in the skeleton code. Your code will be tested using other test programs that expect the given naming. Provided Files: main.py: The Python file you are required to complete and submit. lorem.txt: Sample text file used to test the program. rsa key.pem: RSA private key used by the testing code. rsa sig.pem: RSA private key used by the testing code (for signing messages). 1 Expected Output: The expected output of the testing code provided in the skeleton code is given below. You may wish to test your code further using different inputs. $ python main.py [AES] Successfully Decrypted: True [RSA] Successfully Decrypted: True [RSA] Successfully Imported/Exported: True [HYBRID] Successfully Decrypted: True [SIG] Original Valid: True [SIG] Modified NOT Valid: True [SIG] Original Successfully Decrypted: True [SIG] Modified Fails Decryption: True 2
Comments are closed.