Click here to Skip to main content
11,927,711 members (37,381 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# XML Java cryptography
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 version="1.0" standalone="yes"?>
    <EncryptedData Type="" xmlns=""><EncryptionMethod Algorithm="" />
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:

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 10-Apr-13 23:50pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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..


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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151126.1 | Last Updated 11 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100