Question: In this assignment, you will create a Python program that allows users to upload any given file, encrypt it using the cryptography module, decrypt it
In this assignment, you will create a Python program that allows users to upload any given file, encrypt it using the cryptography module, decrypt it and access the decrypted file. Your program should adhere to PEP formatting guidelines, import the cryptography module, and utilize the correct cryptographic functions for encryption and decryption.
Requirements:
Adhere to PEP formatting guidelines.
Import the cryptography module to utilize cryptographic methods.
Provide a function to generate a cryptographic key if it doesn't exist. If the key exists, retrieve it and use it for encryption and decryption.
Implement encryption and decryption functions using the cryptography module.
Allow users to upload any file type for encryption.
Decrypt the file back to its original file type and state to be executable like the original
Your script should be able to encrypt a file and then be exited. When your script is started again, it needs to decrypt the previously encrypted file file using the same key, without raising an InvalidToken error.
Hints:
The cryptography module is not in the Python standard library and needs to be installed in your virtual environment
Include conditional statements to determine if a cryptography key exists or should be generated
Use a env file and env variables to store any necessary keys securely
Refer to the cryptography documentation for guidance on key generation, encryption, and decryption methods.
String manipulation may be useful for handling file extensions when encrypting and decrypting files
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
