Hi Everyone. <br><br>I am trying to decrypt an xml message in python using XMLSec in python (PyXMLSec) and run into an error message that seems to come from the C xmlsec library.<br>I have found the examples on <a href="http://pyxmlsec.labs.libre-entreprise.org/index.php?section=examples&id=11" target="_blank">http://pyxmlsec.labs.libre-entreprise.org/index.php?section=examples&id=11</a>
and accordingly did the following, but am receiving errors, which I really don't understand. <br>The xml seems to be fine, since I can read the xml file and find the EncryptedData node. <br>The private key file is an RSA private key, which is valid and I can successfully use it in other cryptographic libraries.<br>
I hope anyone can help. Thanks in advance for the effort.<br><br>
Cheers,<br>
<br>
Dolf.<br><br>The python code:<br><br>private_key_file='my.private.key'<br><div id=":iu">xmlstring=open('temp.xml','rb').read()<br><br>import libxml2<br>import xmlsec<br><br>libxml2.initParser()<br>
libxml2.substituteEntitiesDefault(1)<br>
xmlsec.init()<br>xmlsec.cryptoAppInit(None)<br>xmlsec.cryptoInit()<br><br>doc=libxml2.parseMemory(xmlstring,len(xmlstring))<br>node=xmlsec.findNode(doc.getRootElement(),xmlsec.NodeEncryptedData,xmlsec.EncNs)<br>node.get_name()<br>
'''EncryptedData'''<br>print(node.children)<br>'''<EncryptionMethod Algorithm="<a href="http://www.w3.org/2001/04/xmlenc#aes256-cbc" target="_blank">http://www.w3.org/2001/04/xmlenc#aes256-cbc</a>"/>'''<br>
key=xmlsec.keyReadBinaryFile(xmlsec.keyDataRsaId(),private_key_file)<br>'''<br>func=xmlSecKeyDataBinRead:file=keysdata.c:line=349:obj=unknown:subj=id->binRead != NULL:error=100:assertion: <br>func=xmlSecKeyReadBuffer:file=keys.c:line=1190:obj=rsa:subj=xmlSecKeyDataBinRead:error=1:xmlsec library function failed: <br>
func=xmlSecKeyReadBinaryFile:file=keys.c:line=1247:obj=rsa:subj=xmlSecKeyReadBuffer:error=1:xmlsec library function failed:filename=my.private.key<br>'''<br>key.setName(private_key_file)<br>enc_ctx = xmlsec.EncCtx(None)<br>
enc_ctx.encKey=key<br><br>enc_ctx.decrypt(node)<br>'''func=xmlSecEncCtxEncDataNodeRead:file=xmlenc.c:line=809:obj=unknown:subj=encCtx->mimeType == NULL:error=100:assertion: <br>func=xmlSecEncCtxDecryptToBuffer:file=xmlenc.c:line=715:obj=unknown:subj=xmlSecEncCtxEncDataNodeRead:error=1:xmlsec library function failed: <br>
func=xmlSecEncCtxDecrypt:file=xmlenc.c:line=623:obj=unknown:subj=xmlSecEncCtxDecryptToBuffer:error=1:xmlsec library function failed: <br>-1<br>'''</div>