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
Este ejemplo tiene como objetivo cifrar un documento XML mediante el servicio de cifrado de TrustedX. Para la comprensión de este ejemplo, se recomienda haber entendido previamente el ejemplo de Validación de un certificado X.509.
Para poder probar este ejemplo se debe descargar el archivo sampleSW10.zip y seguir las instrucciones que se encuentran en Configuración del entorno. El archivo descargado contiene el código de ejemplo y los archivos necesarios, en este caso el certificado a validar.
El mecanismo utilizado para el cifrado de datos, sirve para asegurar la confidencialidad entre un emisor y un receptor. Este mecanismo, usa el par de claves proporcionados por la infraestructura PKI, es decir la clave privada y la clave pública.
En primer lugar hay que crear el objeto que contendrá la petición en este caso un SmartEncryptRequest e indicar el perfil a utilizar en el caso del cifrado de documentos XML este será XMLENC.
SmartEncryptRequest ser = new SmartEncryptRequest(host);
ser.setProfile(Constants.Profile.XMLENC);
A continuación se introducen los datos a cifrar, en este caso irán codificados en Base64 y se introducen con el método setInputXmlBase64().
ser.setInputXmlBase64(Util.readBinaryFileB64(path_in + filename));
Opcionalmente la petición contiene información acerca de los destinatarios para los que se debe cifrar el mensaje. Para ello se puede utilizar un conjunto de métodos que seleccionaran a los destinatarios en función del parámetro que se le envíe. En este caso se utiliza el metodo setKeySubjectName(), dado que el destinatario se selecciona mediante el nombre distinguido.
ser.setKeySubjectName(distinguishedName);
Una vez se han introducido todos los datos en la petición se invoca la operación send() que envía la petición al host y recoge la respuesta en un objeto SmartEncryptResponse.
SmartEncryptResponse sers = ser.send();
Al ejecutar el ejemplo se podrá visualizar si la operación se ha realizado con éxito y si es así el XML referente a los datos encriptados.
|