diff --git a/pdf_encrypt/PdfDecrypt.py b/pdf_encrypt/PdfDecrypt.py new file mode 100644 index 000000000..2a9aa57e1 --- /dev/null +++ b/pdf_encrypt/PdfDecrypt.py @@ -0,0 +1,10 @@ +import pyAesCrypt +import sys +bufferSize = 64 * 1024 +password = input("password for decrypting : ") +opname = sys.argv[1].replace(".aes", "") +try: + pyAesCrypt.decryptFile(sys.argv[1], opname, password, bufferSize) + print(f"FILE HAS BEEN DECRYPTED SUCCESSFULLY. STORED IN {opname}") +except ValueError: + print("WRONG PASSWORD OR THE FILE IS CORRUPTED") diff --git a/pdf_encrypt/PdfEncrypt.py b/pdf_encrypt/PdfEncrypt.py new file mode 100644 index 000000000..3c7764aad --- /dev/null +++ b/pdf_encrypt/PdfEncrypt.py @@ -0,0 +1,36 @@ +import pyAesCrypt +import sys +import re + +bufferSize = 64 * 1024 + + +def check_password(password): + """ + function to check the strength of password + """ + regex = re.compile('[@_!#$%^&*()<>?/\\|}{~:]') + + t1 = len(password) >= 8 + t2 = not (regex.search(password) is None) + t3 = any(c.islower() for c in password) + t4 = any(c.isupper() for c in password) + t5 = any(c.isdigit() for c in password) + + if t1 and t2 and t3 and t4 and t5: + return True + else: + return False + + +password = input("password for encrypting : ") +password_strength = check_password(password) + +while not password_strength: + print("WEAK Password") + print("Please enter a strong password") + password = input("password for encrypting : ") + password_strength = check_password(password) + +pyAesCrypt.encryptFile(sys.argv[1], f"{sys.argv[1]}.aes", password, bufferSize) +print(f"FILE HAS BEEN ENCRYPTED SUCCESSFULLY. STORED IN {sys.argv[1]}.aes") diff --git a/pdf_encrypt/README.md b/pdf_encrypt/README.md new file mode 100644 index 000000000..14a582633 --- /dev/null +++ b/pdf_encrypt/README.md @@ -0,0 +1,56 @@ +# Using PdfEncrypt and PdfDecrypt Script + +## Steps to encrypt the PDF file : + +1. run the script `PdfEncrypt.py` and pass the path of the file as an argument. +Example : + ``` + python PdfEncrypt.py ./test_file.pdf + ``` + +2. Enter the password when prompted. + + ___NOTE : The password should satisfy the following criteria :___ + - at least 8 characters in length + - at least one lowercase character + - at least one uppercase character + - at least one digit (0-9) + - at least one special character [@_!#$%^&*()<>?/\|}{~:] + + ___Otherwise the password will be classified as weak and you will be asked to enter a strong password as shown below___ + + Example : + ``` + password for encrypting : testpass + WEAK Password + Please enter a strong password + password for encrypting : Test@1234 + ``` + +3. You will get the following prompt with the relative path to the encrypted file. + ``` + FILE HAS BEEN ENCRYPTED SUCCESSFULLY. STORED IN ./test_file.pdf.aes + ``` + +## Steps to decrypt the encrypted PDF file : + +1. run the script `PdfDecrypt.py` and pass the path of the file as an argument. +Example : + ``` + python PdfDecrypt.py ./test_file.pdf.aes + ``` + +2. Enter the password when prompted. +Example : + ``` + password for encrypting : Test@1234 + ``` + +3. On __Successful decryption__ you will get the following prompt with the relative path to the decrypted file. + ``` + FILE HAS BEEN DECRYPTED SUCCESSFULLY. STORED IN ./test_file.pdf + ``` + On __Failure__ you will get the following prompt + ``` + WRONG PASSWORD OR THE FILE IS CORRUPTED + ``` \ No newline at end of file diff --git a/pdf_encrypt/requirements.txt b/pdf_encrypt/requirements.txt new file mode 100644 index 000000000..e002cb57a --- /dev/null +++ b/pdf_encrypt/requirements.txt @@ -0,0 +1 @@ +pyAesCrypt \ No newline at end of file diff --git a/pdf_encrypt/test_file.pdf b/pdf_encrypt/test_file.pdf new file mode 100644 index 000000000..5c19daf6e Binary files /dev/null and b/pdf_encrypt/test_file.pdf differ diff --git a/pdf_encrypt/test_file.pdf.aes b/pdf_encrypt/test_file.pdf.aes new file mode 100644 index 000000000..9b52de4fa Binary files /dev/null and b/pdf_encrypt/test_file.pdf.aes differ