pdf查看密码

pdf有两种密码方式,一种是打开后进入文件内容页面后需要密码才能进行修改等操作,网上有很多方式进行移除密码操作,第二种是打开就需要密码,我这里简单记录一个暴力破解的方式,仅供参考

python 复制代码
import PyPDF2
import itertools
import string

def decrypt_pdf(input_file, output_file, password):
    with open(input_file, "rb") as file:
        reader = PyPDF2.PdfReader(file)

        if reader.is_encrypted:
            try:
                if reader.decrypt(password):
                    writer = PyPDF2.PdfWriter()

                    for page in reader.pages:
                        writer.add_page(page)

                    with open(output_file, "wb") as output_pdf_file:
                        writer.write(output_pdf_file)
                        print(f"解密后文件已保存为: {output_file}")
                        return True
                else:
                    print(f"密码'{password}'错误")
            except Exception as e:
                print(f"解密失败: {e}")
        else:
            print("该 PDF 文件没有加密。")
        return False

def generate_passwords(length):
    characters = string.ascii_letters + string.digits  # 字母加数字方式 可以添加其他字符
    for password in itertools.product(characters, repeat=length):
        yield ''.join(password)

if __name__ == "__main__":
    input_pdf_path = r"d:\"  # 输入你的加密 PDF 文件路径
    output_pdf_path = r"d:\"  # 输出解密后文件的路径

    # 尝试生成长度为1到4的所有可能的密码
    for length in range(1, 5):  # 可调整最大长度
        print(f"尝试长度为 {length} 的密码...")
        for password in generate_passwords(length):
            if decrypt_pdf(input_pdf_path, output_pdf_path, password):
                break
相关推荐
2501_929382655 小时前
MobiOffice解锁高级功能版 v15.9.57971 安卓手机doc, docx ppt, .pptx pdf办公软件
智能手机·pdf·powerpoint·wps
CodeCraft Studio11 小时前
国产化PDF处理控件Spire.PDF教程:如何在 C# 中从 HTML 和 PDF 模板生成 PDF
pdf·c#·html·.net·spire.pdf·pdf文档开发·html创建模板pdf
E_ICEBLUE17 小时前
高效压缩 PDF 文件大小(3 大实用的 Python 库)
python·pdf
技术钱1 天前
vue3 封装图片上传预览组件支持docx、excel、pdf、图片、txt格式
vue.js·pdf·excel
xingxing_F1 天前
PDF Protector for mac PDF文档加密解密工具
macos·pdf
985小水博一枚呀1 天前
【AI大模型学习路线】第三阶段之RAG与LangChain——第十九章(实战基于Advanced RAG的PDF问答)系统部署与测试?
人工智能·学习·langchain·pdf
励志成为美貌才华为一体的女子1 天前
本地用docling实现pdf转markdown操作笔记
笔记·pdf
星空的资源小屋1 天前
RoboIntern,一款自动化办公小助手
运维·人工智能·pdf·自动化·电脑·excel
mucheni2 天前
迅为RK3568开发板OpenHarmony系统南向驱动开发手册-pdf配置 rk3568_uart_config.hcs
驱动开发·pdf
ONLYOFFICE2 天前
ONLYOFFICE 桌面编辑器9.1版本已发布:PDF密文功能和全新注释、工作表公式优化及文件恢复便捷化等
pdf·编辑器·onlyoffice 模板