Python 如何将.cer文件(我拥有的数字签名证书)添加到pdf中?
我想阅读所有的pdf文件并添加一个.cer文件,用证书对pdf文件进行数字签名。添加或删除“encoding='utf-8'”没有任何区别Python 如何将.cer文件(我拥有的数字签名证书)添加到pdf中?,python,pdf,digital-signature,Python,Pdf,Digital Signature,我想阅读所有的pdf文件并添加一个.cer文件,用证书对pdf文件进行数字签名。添加或删除“encoding='utf-8'”没有任何区别 import OpenSSL cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, open('digital_sig/tci.cer', encoding='utf-8').read()) E
import OpenSSL
cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1,
open('digital_sig/tci.cer', encoding='utf-8').read())
ERROR:
---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-7-fc2a32e67543> in <module>()
2
3 cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1,
----> 4 open('digital_sig/tci.cer', encoding='utf-8').read())
~\Anaconda3\lib\codecs.py in decode(self, input, final)
320 # decode input (taking the buffer into account)
321 data = self.buffer + input
--> 322 (result, consumed) = self._buffer_decode(data, self.errors, final)
323 # keep undecoded input until the next call
324 self.buffer = data[consumed:]
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 1: invalid start byte
导入OpenSSL
cert=OpenSSL.crypto.load\u证书(OpenSSL.crypto.FILETYPE\u ASN1,
打开('digital_sig/tci.cer',encoding='utf-8').read())
错误:
---------------------------------------------------------------------------
UnicodeDecodeError回溯(最近一次呼叫最后一次)
在()
2.
3 cert=OpenSSL.crypto.load_证书(OpenSSL.crypto.FILETYPE_ASN1,
---->4打开('digital_sig/tci.cer',encoding='utf-8')。读取()
解码中的~\Anaconda3\lib\codecs.py(self、input、final)
320#解码输入(考虑缓冲区)
321数据=自缓冲+输入
-->322(结果,消耗)=自身缓冲区解码(数据,自身错误,最终)
323#保留未编码的输入直到下一次呼叫
324 self.buffer=数据[消耗:]
UnicodeDecodeError:“utf-8”编解码器无法解码位置1中的字节0x82:无效的开始字节
证书编码为DER,这是一种二进制编码。以二进制模式打开文件:
open('digital_sig/tci.cer', 'rb').read()