下载个PDF居然还要密码?想要密码就付费?这我能忍你!Python分分钟解密它!
?
?
概敘
? ? ? ?今天因?yàn)樾枰玫揭粋€(gè)參考文檔,然后在網(wǎng)上找了一下,就下載了一個(gè)pdf文檔!下載之后居然是加密的,如果要密碼就要給錢?我這暴脾氣,還真不能忍你!
? ? ? ???
想收我得錢,不存在的,接下來(lái)就是破解過(guò)程了!
說(shuō)句題外話,為什么現(xiàn)在越來(lái)越多的文檔都是PDF格式呢?因?yàn)樗强梢浦参臋n格式(PDF)是在線附件中使用最廣泛的文件格式之一。
大多數(shù)文檔,例如電子書、掃描文檔等,都使用這種pdf格式進(jìn)行存儲(chǔ)和共享。
為了在各種平臺(tái)和媒體上共享,文檔面臨著許多威脅,例如信息泄漏和未經(jīng)授權(quán)的個(gè)人訪問(wèn)。因此,一個(gè)人必須對(duì)他/她的文件進(jìn)行加密,以防止這種可以避免的事件和暴露。
Python是一種足智多謀的編程語(yǔ)言,它提供了一個(gè)非常棒的模塊,稱為PyPDF2對(duì)pdf文件進(jìn)行加密和解密,從而增強(qiáng)所包含信息的安全性。
PyPDF 2庫(kù)能夠:
PyPDF2不是內(nèi)置的庫(kù),因此需要先安裝它,然后才能使用:
pip3 install PyPDF2下面的代碼實(shí)現(xiàn)中使用的文件可以找到這里
加密PDF文件
文件加密需要在文檔中添加密碼,從而允許只訪問(wèn)授權(quán)人員。
為此,我們將遵循以下步驟:
步驟1:使用Reader對(duì)象打開(kāi)pdf。
步驟2:通過(guò)迭代創(chuàng)建原始文件的副本
每一頁(yè),并將其添加到新的pdf文件。
步驟3:加密新的pdf文件。
守則執(zhí)行
# Import the required module and sub-modules from PyPDF2 import PdfFileWriter from PyPDF2 import PdfFileReader# Create a PdfFileWriter object result = PdfFileWriter()# Open the pdf file to encrypt file = PdfFileReader('Magazine.pdf')# Retrieve the number of pages to iterate in the original document length = file.numPages# Iterates through every page and adds it to the new file (a copy of the original) for i in range(length):pages = file.getPage(i)result.addPage(pages)# Creates a variable password. password = 'pam&Lab890'# Encrypt the file using the created password result.encrypt(password)# Open a new file 'Magazines.pdf' and write the encrypted pdf file with open('Magazines.pdf','wb') as f:result.write(f)這將創(chuàng)建原始文件的類似副本(可能具有指定的不同名稱),需要設(shè)置密碼才能啟用訪問(wèn)。
解密PDF文件
解密用給定的密碼解鎖文檔,并將其轉(zhuǎn)換為不需要密碼密鑰訪問(wèn)的pdf文件。
文件解密步驟與加密步驟幾乎類似。
步驟1:使用Reader對(duì)象打開(kāi)pdf。
步驟2:加密新的pdf文件。
步驟3:通過(guò)迭代創(chuàng)建原始文件的副本
每一頁(yè),并將其添加到新的pdf文件。
守則執(zhí)行
# Import the required module and sub-modules from PyPDF2 import PdfFileWriter from PyPDF2 import PdfFileReader# Create a PdfFileWriter object result = PdfFileWriter()# Open the password - secured pdf file to decrypt file = PdfFileReader('Magazines.pdf')# Creates a variable password. password = 'pam&Lab890'# First, check if the file is encrypted then proceed if encrypted if file.isEncrypted:# Decrypt the file using the givenpassword file.decrypt(password)# Iterates through every page and adds it to the new file for i in range(31):pages = file.getPage(i)result.addPage(pages)# Open a new file 'Magazines1.pdf' and write the encrypted pdf filewith open('Magazines1.pdf','wb') as f:result.write(f)print('File decrypted successfully')else:print('File is not encrypted')如果你們發(fā)現(xiàn)這篇文章很有幫助,那么保存它,這樣你就可以隨時(shí)參考:shaush:。對(duì)于那些想了解更多關(guān)于PyPDF 2模塊和功能的人,只需在下面的注釋部分中推薦特定的區(qū)域(是否合并、拆分e.t.c)。
???
需要完整代碼:點(diǎn)這里即可
總結(jié)
以上是生活随笔為你收集整理的下载个PDF居然还要密码?想要密码就付费?这我能忍你!Python分分钟解密它!的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: PDF解密网站
- 下一篇: Android文件存储---内部存储,外