from docx import Document
from Crypto.Cipher import AES
document = Document('test.docx')
allText = ""
for docpara in document.paragraphs:
allText+=(docpara.text)
key="1234567891011121"
cipher=AES.new(key,AES.MODE_ECB)
msg=cipher.encrypt(allText)
当我运行下面的代码时,我想在python.But中加密一个Docx文件:
提升类型(“对象类型%s不能传递给C代码”%TypeError(Data))
TypeError:对象类型不能传递给C代码
我该如何解决这个问题?
发布于 2018-07-12 16:45:42
从文档中:
>>> from Crypto.Cipher import AES
>>> from Crypto import Random
>>>
>>> key = b'Sixteen byte key'
>>> iv = Random.new().read(AES.block_size)
>>> cipher = AES.new(key, AES.MODE_CFB, iv)
>>> msg = iv + cipher.encrypt(b'Attack at dawn')
我认为你的密钥需要先转换成字节,对象也需要加密。请注意两者之前的b'
。
您还需要添加用于加密的初始化向量(iv)。
https://stackoverflow.com/questions/51300497
复制相似问题