Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pdf_encrypt/PdfDecrypt.py
Original file line number Diff line number Diff line change
@@ -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")
36 changes: 36 additions & 0 deletions pdf_encrypt/PdfEncrypt.py
Original file line number Diff line number Diff line change
@@ -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")
56 changes: 56 additions & 0 deletions pdf_encrypt/README.md
Original file line number Diff line number Diff line change
@@ -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
```
1 change: 1 addition & 0 deletions pdf_encrypt/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyAesCrypt
Binary file added pdf_encrypt/test_file.pdf
Binary file not shown.
Binary file added pdf_encrypt/test_file.pdf.aes
Binary file not shown.