Hi Wolfgang, I'm not sure what's wrong with the sample, but I can tell that I've used the APIs to successfully encrypt and decrypt SAML messages with: a) the entire <Assertion> element and all sub-elements encrypted b) several different <Attribute> elements encrypted
Michael A. Lucas -----Original Message----- From: Wolfgang Freis [mailto:[EMAIL PROTECTED] Sent: October 30, 2007 1:47 PM To: security-dev@xml.apache.org Subject: Still stuck with problem. Re: Problem decrypting elements Hello all, I'm still stuck with this problem and don't know what else to try. I'm basically using the sample code with some modifications to handle multiple elements. Encryption works fine with child elements or contents both when a single or multiple elements with the same name are encrypted. However, decryption only works when there is a single element or content node to decrypt. If there are more, an exception is thrown: Oct 30, 2007 2:28:18 PM org.apache.xml.security.encryption.XMLCipher decryptToByteArray SEVERE: XMLCipher::decryptElement called without a key and unable to resolve Exception in thread "main" org.apache.xml.security.encryption.XMLEncryptionException: No Key Encryption Key loaded and cannot determine using key resolvers Stepping through the code in my IDE, I can see that the key gets loaded. What is missing, though, is the KeyInfo. Method decryptToByteArray(Element element) in class XMLCipher tries to get the KeyInfo: KeyInfo ki = encryptedData.getKeyInfo(); When ki gets evaluated it is null, however, and the exception is thrown. Again, it only happens when multiple elements are encrypted. Obviously, I'm missing something here but neither the documentation nor the email archive have given me any clues on how to solve this. Any help will be greatly appreciated. Thanks, Wolfgang Quoting Wolfgang Freis <[EMAIL PROTECTED]>: > Hello, > > I'm new to working with XML encryption and have come across a problem. > Neither the email archive nor have brought me closer to a solution. > > Google Starting with the sample files Encrypter.java and > Decrypter.java I have managed to en- and decrypt elements by name. > However, decryption works only when there is only one element > encrypted. If I encrypt multiple elements by name--as siblings or as > children of different parents--the decryptor throws an exception: > > Oct 26, 2007 3:56:45 PM org.apache.xml.security.encryption.XMLCipher > decryptToByteArray > SEVERE: XMLCipher::decryptElement called without a key and unable to > resolve > Exception in thread "main" > org.apache.xml.security.encryption.XMLEncryptionException: > No Key Encryption Key loaded and cannot determine using key > resolvers > > My IDE tells that the key file was loaded and, as I said, the > decryption works fine when only one element of the XML is encrypted. > I tried decrypting by iterating over the NodeList returned from > getElementsByTagNameNS(namespaceURI, localName) and trying to just > grab the first item. Both generate the same exception. From what I > can see in the IDE is that the method decryptToByteArray(Element > element) called from > doFinal( document, encryptedDataElement) throws the exception, but it > escapes me why that happens. > > Any help will be greatly appreciated. > > Thanks, > Wolfgang > > >