|
PERMISION NOTICE AND DISCLAIMER This website contains certain downloadable software. This software is copyrighted and the copyrighter claims all exclusive rights to such software. The copyright owner of the software that you download through this site may be indicated in the accompanying read-me file and in the accompanying source code as well as in the area of this Web Site from which the software is downloaded. Permission to use, copy, modify and distribute this software and its source code for non commercial purposes and without fee is hereby granted, provided that the name of the copyright owner or related contributors not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. The copyright owner and contributors makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. The copyright owner and its contributors disclaim all warranties with regard to this software, including all implied warranties of merchantability and fitness. In no event shall the author and the contributors be liable for any special, indirect or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or other tortuous action, arising out of or in connection with the use or performance of this software. AcceptCancel
The objective of this example is to decrypt an XML document using the TrustedX decryption service. In order to understand this example, it is recommended that first you understand the previously seen example: XML Encryption.
To try this example, you must download the file called sampleAxis10.zip and follow the instructions in Configuration of the Environment.
The content to be decrypted is the one generated in the XML Encryption example. The downloaded file already contains an encrypted document, but, if you wish, you can replace this document with the one generated in the previous example, to check that it functions correctly.
The method used for decrypting the XML documents is complementary to the encryption method. The decryption request is included inside a DecryptRequest object.
DecryptRequest dr = new DecryptRequest();
dr.setProfile(new URI(PROF_XML_DECRYPT));
UtilTrustedX.addUsernameToken(bindingDe, user, password);
The request includes the data to be decrypted, which must be included in an EnvelopedObject object. In this case, we include the content in XML format.
EnvelopedObject eobj = new EnvelopedObject();
String filecontent = Util.readFile(path_in + encryptedfile);
AnyType any = new AnyType();
MessageElement me = getMessageElementFromString(filecontent);
any.set_any(new MessageElement[]{me});
eobj.setXMLEnvelope(any);
dr.setEnvelopedObject(eobj);
Once all the data have been entered in the request, the decrypt() operation is invoked; this operation sends the request to the host and collects the response in a DecryptResponse object.
DecryptResponse drs = bindingDe.decrypt(dr);
Finally, after executing the example, we obtain a DemoEncryptedDecrypted.xml file with the decrypted content. This can be compared with the content of the file that was encrypted in the XML Encryption example to see if they are, indeed, the same.
|