Click here to Skip to main content
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 OriginalGriff 381
1 Praneet Nadkar 237
2 Marcin Kozub 225
3 Sergey Alexandrovich Kryukov 195
4 Shweta N Mishra 161
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,327
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,920


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 11 Apr 2013
Copyright © CodeProject, 1999-2014
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