You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@santuario.apache.org by Björn-Peter Tietjens <bt...@intersales.de> on 2009/08/11 10:36:27 UTC
decrypting
Hi,
I am encrypting xml using the sample code.
But I have a problem decrypting it.
I have a String representation of the encrypted xml: see below
I want to get a org.w3c.dom.Document representation by parsing that
String and then decrypt the Document as in the sample code:
public Document getDocFromString(string data) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = null;
StringReader sr = new StringReader(data);
InputSource is = new InputSource(sr);
document = builder.parse(is);
return document;
}
For some reason my returned document is always a DeferredDocumetnImpl
and at the point where the decrypter gets the encryptedDataElement:
Element encryptedDataElement = (Element)
document.getElementsByTagNameNS(EncryptionConstants.EncryptionSpecNS,EncryptionConstants._TAG_ENCRYPTEDDATA).item(0);
the NodeList returned by getElementsByTagNameNS() is always empty.
Does anyone have anyidea why that could be?
the encrypted xml:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
Type="http://www.w3.org/2001/04/xmlenc#Element">
<xenc:EncryptionMethod
Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"
xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"/>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod
Algorithm="http://www.w3.org/2001/04/xmlenc#kw-tripledes"
xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"/>
<xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:CipherValue
xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">7o7fVsLQUcvrZnxY1OI5N/1knMyeaiuFI3Qke4SNTpc=</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedKey>
</ds:KeyInfo>
<xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:CipherValue
xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">2PXqMwpgeDscrfdYFu+5J5mVSjFPHHlOzUwTwByyTsxoQa7W5Jv3GpOyezRRHYH53dX4xUmypcuA
TOSsghGmodw3AOD1NS/k4OSia9lv8/Wc1jEua6LBz6H3Hhw78yB2Xjg0AW2OziyPRZ3q+5HHKWcY
d1iRK8xmx/IFD12Gg2KPO49xuHW5OVvw40WpBUbHpwgevZ1Ua5jYljNPzVyGuFODPAJFdAmoaQbm
pWZi/L00rQRTKMbPRtDStt5KJU3DEO/8RIUc5poeDTezELt84flXxuxe0iF7HX552aenyH2InHz1
uoTWhOqTELh/R5XdgO5fXRanHh3bezwIjRIUza3v6WpQzoWhVTTphDMQgz66nvzE9F2TgZ2OGgrR
ZKL/Nk7/E9x09OpUQZuJCCxehXawWrU3Mb3Y59pTC6zkLr49XaaZBz5uIGmQ+zlIgWaADIrW7Q6D
1K9veazsle70uA==</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
Re: decrypting
Posted by Sean Mullan <Se...@Sun.COM>.
You must enable the DocumentBuilderFactory to be namespace aware before
parsing the document, add this line:
factory.setNamespaceAware(true);
--Sean
Björn-Peter Tietjens wrote:
> Hi,
>
> I am encrypting xml using the sample code.
>
> But I have a problem decrypting it.
> I have a String representation of the encrypted xml: see below
> I want to get a org.w3c.dom.Document representation by parsing that
> String and then decrypt the Document as in the sample code:
>
> public Document getDocFromString(string data) {
> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
> DocumentBuilder builder = factory.newDocumentBuilder();
> Document document = null;
> StringReader sr = new StringReader(data);
> InputSource is = new InputSource(sr);
> document = builder.parse(is);
> return document;
> }
>
> For some reason my returned document is always a DeferredDocumetnImpl
> and at the point where the decrypter gets the encryptedDataElement:
>
> Element encryptedDataElement = (Element)
> document.getElementsByTagNameNS(EncryptionConstants.EncryptionSpecNS,EncryptionConstants._TAG_ENCRYPTEDDATA).item(0);
>
>
> the NodeList returned by getElementsByTagNameNS() is always empty.
>
> Does anyone have anyidea why that could be?
>
> the encrypted xml:
> <?xml version="1.0" encoding="utf-8" standalone="yes"?>
> <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
> Type="http://www.w3.org/2001/04/xmlenc#Element">
> <xenc:EncryptionMethod
> Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"
> xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"/>
> <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
> <xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
> <xenc:EncryptionMethod
> Algorithm="http://www.w3.org/2001/04/xmlenc#kw-tripledes"
> xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"/>
> <xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
> <xenc:CipherValue
> xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">7o7fVsLQUcvrZnxY1OI5N/1knMyeaiuFI3Qke4SNTpc=</xenc:CipherValue>
>
> </xenc:CipherData>
> </xenc:EncryptedKey>
> </ds:KeyInfo>
> <xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
> <xenc:CipherValue
> xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">2PXqMwpgeDscrfdYFu+5J5mVSjFPHHlOzUwTwByyTsxoQa7W5Jv3GpOyezRRHYH53dX4xUmypcuA
>
> TOSsghGmodw3AOD1NS/k4OSia9lv8/Wc1jEua6LBz6H3Hhw78yB2Xjg0AW2OziyPRZ3q+5HHKWcY
>
> d1iRK8xmx/IFD12Gg2KPO49xuHW5OVvw40WpBUbHpwgevZ1Ua5jYljNPzVyGuFODPAJFdAmoaQbm
>
> pWZi/L00rQRTKMbPRtDStt5KJU3DEO/8RIUc5poeDTezELt84flXxuxe0iF7HX552aenyH2InHz1
>
> uoTWhOqTELh/R5XdgO5fXRanHh3bezwIjRIUza3v6WpQzoWhVTTphDMQgz66nvzE9F2TgZ2OGgrR
>
> ZKL/Nk7/E9x09OpUQZuJCCxehXawWrU3Mb3Y59pTC6zkLr49XaaZBz5uIGmQ+zlIgWaADIrW7Q6D
>
> 1K9veazsle70uA==</xenc:CipherValue>
> </xenc:CipherData>
> </xenc:EncryptedData>
>