python导出excel文件数字签名,如何使用带有etoken(笔驱动器)的Python对PDF文档进行数字签名?...

How to digitally sign PDF documents using Python? I have an etoken (in pen drive).

Additionally, I have created an excel file using openpyxl and converted it into PDF. Now there is a requirement that I need to add digital signature to that PDF document.

Is there any way I can achieve this in python?

解决方案

Use python module designed for this task, it signs digitally PDF-s.

Everything what You should have is p12/pfx file with certificate.

#!/usr/bin/env python3

# *-* coding: utf-8 *-*

from oscrypto import asymmetric

from endesive import pdf

def main():

dct = {

b'sigflags': 3,

b'contact': b'me@email.com',

b'location': b'City',

b'signingdate': b'20180731082642+02\'00\'',

b'reason': b'Some descriptive message',

}

p12 = asymmetric.load_pkcs12(

open('demo2_user1.p12', 'rb').read(),

'1234'

)

datau = open('pdf.pdf', 'rb').read()

datas = pdf.cms.sign(datau, dct, p12[0], p12[1], [], 'sha256')

with open('pdf-signed-cms.pdf', 'wb') as fp:

fp.write(datau)

fp.write(datas)

main()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值