Click here to Skip to main content
16,018,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone

I have encrypted an xml using 128 bit AES using C# "RijndaelManaged" Class. I hardcoded the IV and key bytes. My encrypted XML looks like this.

XML
<?xml version="1.0" standalone="yes"?>
<Data>
    <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#"><EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc" />
        <CipherData>
            <CipherValue>ZW97bGRnZHljagIZZV0Ifq160IptZMvv</CipherValue>
        </CipherData>
    </EncryptedData>
</Data>

Can anyone tell me the java code to decrypt this...
I have tried a few from net but I have not been successful so far.. Please help!

I think I am stuck here in Java Code:

Java
NodeList list = doc.getElementsByTagName("EncryptedData");
Element node = (Element)list.item(0);
String val = node.getNodeValue();
//create the decryption context
DOMDecryptContext dctx = new DOMDecryptContext(keys, node);
//unmarshal encrypted data
EncryptedData encdata = (EncryptedData)fac.unmarshalEncryptedType(dctx);

javax.crypto.spec.IvParameterSpec ivspec = new javax.crypto.spec.IvParameterSpec(ivbyte);
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance("AES/CBC/NoPadding");
cipher.init(javax.crypto.Cipher.DECRYPT_MODE, keys, ivspec);

byte[] bytes = encdata.getEncoding().getBytes();
byte[] decrypted = cipher.doFinal(node.); //Stuck here... No idea what to pass here
String str = new String(decrypted);
Posted
v3

1 solution

 
Share this answer
 
Comments
umarbangash 11-Apr-13 7:44am    
hey thnx for the response but I have to be able to pass the "EncryptedData" Element to the method to get my XML Element in response.

This was my XML before encryption in C#... I used getElementsByName("Person") method in C# and transformed them into the "EncryptedData" element as shown above..



<Person>
<id>OFF4645312
<name>fdsgsd
<unit_id>BAORI172129499227440
<rank_id>GHQ7021279705451622
<service_no>-
<appointments_id>GHQ1201279598508091
<dob>1950-05-04T00:00:00+05:00
</Person>


I hope u understand!
Richard MacCutchan 11-Apr-13 11:48am    
I hope u understand
Not really, and this has nothing to do with XML. You have an encrypted string and its key, so you should be able to decrypt it. The link I gave you is a sample solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900