Click here to Skip to main content
Rate this: bad
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 at 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 at 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
0 OriginalGriff 650
1 Maciej Los 525
2 Suvendu Shekhar Giri 229
3 Sascha Lefévre 229
4 Richard Deeming 195
0 Sergey Alexandrovich Kryukov 9,693
1 OriginalGriff 9,185
2 Peter Leow 5,112
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 2,876

Advertise | Privacy | Mobile
Web01 | 2.8.150327.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