ENCRYPT AND DECRYPT PDFs
Source Code:-
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | # Required Module:- pip install pikepdf########------ENCRYPT THE PDF------#############import pikepdf# Open the PDFpdf = pikepdf.open("D:/My_Pdf.pdf") # Encrypt the Given PDF and make two different Passwords as Public Key & Private Keyencrypt = pikepdf.Encryption(owner = "123456", user = "654321", R = 4)# Save the Encrypted PDFpdf.save('D:/Encrypted PDF.pdf', encryption = encrypt) # Print a Messageprint("Your PDF Encrypted Successfully.")# Close the PDFpdf.close()#*#*#*#*#*#*#*#*#*#*#*#*#*#**#*#*#*#*#*#*#*#*#*#*#*#*#*#*#########------DECRYPT THE PDF------#############import pikepdf# Open the encrypted PDF and Decrypt it using given Passwordpdf = pikepdf.open('D:/Encrypted PDF.pdf', password='654321')# Save the Decrypted PDFpdf.save('Decrypted PDF.pdf') |
# Required Module:- pip install pikepdf
########------ENCRYPT THE PDF------#############
import pikepdf
# Open the PDF
pdf = pikepdf.open("D:/My_Pdf.pdf")
# Encrypt the Given PDF and make two different Passwords as Public Key & Private Key
encrypt = pikepdf.Encryption(owner = "123456", user = "654321", R = 4)
# Save the Encrypted PDF
pdf.save('D:/Encrypted PDF.pdf', encryption = encrypt)
# Print a Message
print("Your PDF Encrypted Successfully.")
# Close the PDF
pdf.close()
#*#*#*#*#*#*#*#*#*#*#*#*#*#**#*#*#*#*#*#*#*#*#*#*#*#*#*#*#
########------DECRYPT THE PDF------#############
import pikepdf
# Open the encrypted PDF and Decrypt it using given Password
pdf = pikepdf.open('D:/Encrypted PDF.pdf', password='654321')
# Save the Decrypted PDF
pdf.save('Decrypted PDF.pdf')
0 Comments