Click here to Skip to main content
11,487,793 members (74,304 online)
Rate this: bad
good
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"?>
<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:

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
v3

1 solution

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

Solution 1

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



<Person>
OFF4645312
fdsgsd
BAORI172129499227440
GHQ7021279705451622
-
GHQ1201279598508091
1950-05-04T00:00:00+05:00
</Person>


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 Sergey Alexandrovich Kryukov 9,193
1 OriginalGriff 8,287
2 Sascha Lefèvre 3,334
3 Maciej Los 2,946
4 Richard Deeming 2,370


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