[xmlsec] hybrid encrypted data for multiple recipients doesn't find keys in Keymanager after first during decryption

Bundschuh, Goetz Goetz.Bundschuh at usd.de
Fri Oct 21 03:19:34 PDT 2005

i have implemented an application with xmlsec that encrypts data for
multiple recipients using RSA 1_5/AES256 hybrid encryption. The AES Session
keys are stored as <EncryptedKey>'s, identified by <Keyname> (Example
below). Encryption works fine.
During decryption of the data, xmlsec only finds private decryption keys in
the Keystore I provide, if the <EncryptedKey> in the <KeyInfo> structure is
the first in the list. The Data is decrypted, everything works fine.. For
all other recipients I get the "Key not found" error, even if their key is
present in the Keymanager(with the correct <KeyName>). I checked the
XmlEncryption spec, the structure for the Encrypted Keys seems to be
correct. I'm using xmlsec 1.2.8 under WinXPSP2, using mscrypto.
Do i have to parse and modify the <EncryptedKey>-List myself for this to
work, or is there something to do with the Keymanager? Thanks.


Structure of an encrypted File, decryption will work only for key "DE,
Langen, usd de ag, it security, Goetz Bundschuh-DC00", not for "de, TU
Darmstadt, FB20, Goetz Bundschuh-6E", even if the private key with that name
is present in the Keymanager: 

<?xml version="1.0" encoding="UTF-8"?>
<EncryptedData xmlns="http://www.w3.org/2001/04/xmlenc#"
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>DE, Langen, usd de ag, it security, Goetz Bundschuh-DC00</KeyName>
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>de, TU Darmstadt, FB20, Christian Valentin-6E</KeyName>

Here is the decryption code I use, adapted from the session key example:

int decryptData(xmlDocPtr doc, xmlSecKeysMngrPtr privKeyMngr) 
    xmlNodePtr      node   = NULL;
    xmlSecEncCtxPtr encCtx = NULL;
    int result = CRYPTERR_OK;
    /* find start node */
    node = xmlSecFindNode(xmlDocGetRootElement(doc),
xmlSecNodeEncryptedData, xmlSecEncNs);
    if(node == NULL) 
		//Could not find start node of document
		goto done;
    /* create decryption context */
    encCtx = xmlSecEncCtxCreate(privKeyMngr);
    if(encCtx == NULL) 
        //failed to create encryption context
		goto done;

    /* decrypt the data */
    if((xmlSecEncCtxDecrypt(encCtx, node) < 0) || (encCtx->result == NULL)) 
		//decryption failed;
		goto done;
    /* cleanup */
    if(encCtx != NULL) 
    return result;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3328 bytes
Desc: not available
Url : http://www.aleksey.com/pipermail/xmlsec/attachments/20051021/d0fe361a/smime-0002.bin

More information about the xmlsec mailing list