[xmlsec] xmlsec problem with decrypting EncryptedData using rsa 1.5 encrypted key for symmetric aes256-cbc algorithm key

Dolf Andringa dolfandringa at gmail.com
Tue Feb 21 13:33:05 PST 2012


Hi Everyone.

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.
I have found the examples on
http://pyxmlsec.labs.libre-entreprise.org/index.php?section=examples&id=11and
accordingly did the following, but am receiving errors, which I really
don't understand.
The xml seems to be fine, since I can read the xml file and find the
EncryptedData node.
The private key file is an RSA private key, which is valid and I can
successfully use it in other cryptographic libraries.
I hope anyone can help. Thanks in advance for the effort.

Cheers,

Dolf.

The python code:

private_key_file='my.private.key'
xmlstring=open('temp.xml','rb').read()

import libxml2
import xmlsec

libxml2.initParser()
libxml2.substituteEntitiesDefault(1)
xmlsec.init()
xmlsec.cryptoAppInit(None)
xmlsec.cryptoInit()

doc=libxml2.parseMemory(xmlstring,len(xmlstring))
node=xmlsec.findNode(doc.getRootElement(),xmlsec.NodeEncryptedData,xmlsec.EncNs)
node.get_name()
'''EncryptedData'''
print(node.children)
'''<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc
"/>'''
key=xmlsec.keyReadBinaryFile(xmlsec.keyDataRsaId(),private_key_file)
'''
func=xmlSecKeyDataBinRead:file=keysdata.c:line=349:obj=unknown:subj=id->binRead
!= NULL:error=100:assertion:
func=xmlSecKeyReadBuffer:file=keys.c:line=1190:obj=rsa:subj=xmlSecKeyDataBinRead:error=1:xmlsec
library function failed:
func=xmlSecKeyReadBinaryFile:file=keys.c:line=1247:obj=rsa:subj=xmlSecKeyReadBuffer:error=1:xmlsec
library function failed:filename=my.private.key
'''
key.setName(private_key_file)
enc_ctx = xmlsec.EncCtx(None)
enc_ctx.encKey=key

enc_ctx.decrypt(node)
'''func=xmlSecEncCtxEncDataNodeRead:file=xmlenc.c:line=809:obj=unknown:subj=encCtx->mimeType
== NULL:error=100:assertion:
func=xmlSecEncCtxDecryptToBuffer:file=xmlenc.c:line=715:obj=unknown:subj=xmlSecEncCtxEncDataNodeRead:error=1:xmlsec
library function failed:
func=xmlSecEncCtxDecrypt:file=xmlenc.c:line=623:obj=unknown:subj=xmlSecEncCtxDecryptToBuffer:error=1:xmlsec
library function failed:
-1
'''
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.aleksey.com/pipermail/xmlsec/attachments/20120221/0bfde3e9/attachment.html>


More information about the xmlsec mailing list