<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic XML document with a digital signature in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/XML-document-with-a-digital-signature/m-p/2292830#M65867</link>
    <description>&lt;P&gt;&lt;SPAN class=""&gt;Hi, I need generate an XML document with a digital signature.&lt;BR /&gt;Example of XML document that I must sign and verify your signature:&amp;nbsp;&lt;BR /&gt;&lt;A href="https://www.efactura.dgi.gub.uy/files/ejemplo-de-sobre?es" target="_self" rel="nofollow noopener noreferrer"&gt;https://www.efactura.dgi.gub.uy/files/ejemplo-de-sobre?es&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;I am a programmer (PHP, C++, Python, NodeJs, etc..), but I do not work with the Java language.&lt;BR /&gt;&lt;BR /&gt;How can I generate plugins for the designer of Talend Data Integration&amp;nbsp;could sign my XMl document and the signature is verified. Any recommendation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;&lt;BR /&gt;&lt;EM&gt;Guide translated from Spanish -&lt;/EM&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;EM&gt; &lt;A href="http://www.efactura.dgi.gub.uy/files/guias-en-el-uso-de-xmlencryption-11062014-pdf?es" target="_self" rel="nofollow noopener noreferrer"&gt;http://www.efactura.dgi.gub.uy/files/guias-en-el-uso-de-xmlencryption-11062014-pdf?es&lt;/A&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;Using the XMLEncryption standard (&lt;A href="http://www.w3.org/2001/04/xmlenc" target="_blank" rel="nofollow noopener noreferrer"&gt;http://www.w3.org/2001/04/xmlenc&lt;/A&gt;).&lt;BR /&gt;It should be used as an asymmetric algorithm rsa-pkcs1 (&lt;A href="http://www.w3.org/2001/04/xmlenc#rsa-1_5" target="_blank" rel="nofollow noopener noreferrer"&gt;http://www.w3.org/2001/04/xmlenc#rsa-1_5&lt;/A&gt;) and&lt;BR /&gt;as a symmetric algorithm: 3DES-CBC (&lt;A href="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" target="_blank" rel="nofollow noopener noreferrer"&gt;http://www.w3.org/2001/04/xmlenc#tripledes-cbc&lt;/A&gt;).&lt;BR /&gt;Finally, as a key name (KeyName), CERT_DGI_EFACTURA must be used.&lt;/P&gt; 
&lt;P&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;The public and private keys are generated in the following way:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;1- &lt;SPAN class=""&gt;&lt;SPAN&gt;As a first step, we create the private key pair (cakey.pem) and public key (cacert.pem) of our CA using the RSA algorithm (since DSA only serves to sign).&lt;/SPAN&gt; A bit length (2048) is chosen according to the security that a CA needs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;openssl req -x509 -newkey rsa:4096 -days 3650 -keyout ca\private\cakey.pem -out ca\cacert.pem -config openssl.cfg&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;2- The pair of private keys (clientkey.pem) and CSR (client.cert.req) that will be sent to the CA are created for the Client (CSR stands for Certificate Signing Request or Certificate Signing Request).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;openssl req -newkey rsa:1024 -keyout client\private\clientkey.pem -out client\csr\client.cert.req -config openssl.cfg&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;3- &lt;SPAN class=""&gt;From the Client's CSR (client.cert.req), a signed X509 certificate (version 3) is created with the private key of the CA (clientcert.pem).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;openssl ca -days 3650 -in client\csr\client.cert.req -out client\signed\clientcert.pem -config openssl.cfg&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;4- &lt;SPAN class=""&gt;Finally, the client's private key (clientkey.pem) and its certificate issued by the CA (clientcert.pem) are exported to PKCS # 12 (client.p12).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;openssl pkcs12 -export -out client\client.p12 -inkey client\private\clientkey.pem -in client\signed\clientcert.pem&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;&lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Example implementation in Java.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;import java.security.PrivateKey;
import java.security.PublicKey;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.xml.security.encryption.EncryptedData;
import org.apache.xml.security.encryption.EncryptedKey;
import org.apache.xml.security.encryption.XMLCipher;
import org.apache.xml.security.keys.KeyInfo;
import org.apache.xml.security.utils.EncryptionConstants;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class XMLEncryptionSample {
 static {
  org.apache.xml.security.Init.init();
 }
 private static Document parseFile(String fileName) throws Exception {
  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  dbf.setNamespaceAware(true);
  DocumentBuilder db = dbf.newDocumentBuilder();
  return db.parse(fileName);
 }
 private static SecretKey generateSymmetricKey() throws Exception {
  String jceAlgorithmName = "DESede";
  KeyGenerator keyGenerator = KeyGenerator.getInstance(jceAlgorithmName);
  return keyGenerator.generateKey();
 }
 private static void writeDocToFile(Document doc, String fileName)
 throws Exception {
  FileOutputStream outStream = new FileOutputStream(new File(fileName));
  TransformerFactory factory = TransformerFactory.newInstance();
  Transformer transformer = factory.newTransformer();
  transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
  DOMSource source = new DOMSource(doc);
  transformer.transform(source, new StreamResult(outStream));
  outStream.close();
 }
 public static void encrypt(String source, String target, String ns, String element,
  Key publicKey, String keyName) throws Exception {
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Read XML from file&lt;/SPAN&gt;&lt;/SPAN&gt;
  Document document = parseFile(source);
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Generates symmetric key for 3Des&lt;/SPAN&gt;&lt;/SPAN&gt;
  Key symmetricKey = generateSymmetricKey();
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Initialize cipher to encrypt the symmetric key&lt;/SPAN&gt;&lt;/SPAN&gt;
  XMLCipher keyCipher = XMLCipher.getInstance(XMLCipher.RSA_v1dot5);
  keyCipher.init(XMLCipher.WRAP_MODE, publicKey);
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class="alt-edited"&gt;Encrypts the symmetric key&lt;/SPAN&gt;&lt;/SPAN&gt;
  EncryptedKey encryptedKey = keyCipher
   .encryptKey(document, symmetricKey);
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Specifies the element of the XML document to be encrypted&lt;/SPAN&gt;&lt;/SPAN&gt;
  Element rootElement = document.getDocumentElement();
  Element elementToEncrypt = rootElement;
  if (element != null) {
   elementToEncrypt = (Element) rootElement.getElementsByTagNameNS(
    ns, element).item(0);
   if (elementToEncrypt == null) {
    System.err.println("T&lt;SPAN class="short_text"&gt;&lt;SPAN class="alt-edited"&gt;he element is not found&lt;/SPAN&gt;&lt;/SPAN&gt;: " + element);
   }
  }
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Initialize cipher to encrypt the XML Element&lt;/SPAN&gt;&lt;/SPAN&gt;
  XMLCipher xmlCipher = XMLCipher.getInstance(XMLCipher.TRIPLEDES);
  xmlCipher.init(XMLCipher.ENCRYPT_MODE, symmetricKey);
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Add information from the encryption key&lt;/SPAN&gt;&lt;/SPAN&gt;
  EncryptedData encryptedDataElement = xmlCipher.getEncryptedData();
  KeyInfo innerKeyInfo = new KeyInfo(document);
  innerKeyInfo.addKeyName(keyName);
  encryptedKey.setKeyInfo(innerKeyInfo);
  KeyInfo keyInfo = new KeyInfo(document);
  keyInfo.add(encryptedKey);
  encryptedDataElement.setKeyInfo(keyInfo);
  // Cipher
  xmlCipher.doFinal(document, elementToEncrypt);
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Write the result in the destination file&lt;/SPAN&gt;&lt;/SPAN&gt;
  writeDocToFile(document, target);
 }
 public static void decrypt(String source, String target, Key privateKey)
 throws Exception {
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Read XML from file&lt;/SPAN&gt;&lt;/SPAN&gt;
  Document document = parseFile(source);
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Get the XML Element with encrypted data&lt;/SPAN&gt;&lt;/SPAN&gt;
  String namespaceURI = EncryptionConstants.EncryptionSpecNS;
  String localName = EncryptionConstants._TAG_ENCRYPTEDDATA;
  Element encryptedDataElement = (Element) document
   .getElementsByTagNameNS(namespaceURI, localName).item(0);
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;The symmetric key is decrypted&lt;/SPAN&gt;&lt;/SPAN&gt;
  XMLCipher xmlCipher = XMLCipher.getInstance();
  xmlCipher.init(XMLCipher.DECRYPT_MODE, null);
  xmlCipher.setKEK(privateKey);
  // &lt;SPAN class=""&gt;The encrypted node is replaced with the decrypted information&lt;/SPAN&gt;
  xmlCipher.doFinal(document, encryptedDataElement);
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Write the result in the destination file&lt;/SPAN&gt;&lt;/SPAN&gt;
  writeDocToFile(document, target);
 }
}&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;Loading the private and public key from a keystore (# PCKS12) named client.p12 whose alias is client, can be programmed as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;PrivateKey privateKey = null;
PublicKey publicKey = null;
....
....
KeyStore keystore = KeyStore.getInstance("PKCS12");
String p12Password = "secreto";
keystore.load(new FileInputStream("client.p12"), p12Password.toCharArray());
privateKey = (PrivateKey) keystore.getKey("client", p12Password.toCharArray());
publicKey = keystore.getCertificate("client").getPublicKey();&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;Finally, to perform a test, the encrypt / decrypt methods can be used as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;encrypt("Unencrypted.xml", "Encrypted.xml", "http://cfe.dgi.gub.uy", "Compl_Fiscal_Data",
publicKey, "CERT_DGI_EFACTURA");

decrypt("Encrypted.xml", "Decrypted.xml", privateKey);&lt;/PRE&gt; 
&lt;P&gt;&lt;SPAN class=""&gt;&lt;BR /&gt;Excuse me if my English is not understood correctly.&lt;BR /&gt;&lt;BR /&gt;Thank you, I hope that I can integrate this into my project in Talend Data Integration with your help.&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="short_text"&gt;Regards&lt;/SPAN&gt;.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 16 Nov 2024 08:21:38 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-11-16T08:21:38Z</dc:date>
    <item>
      <title>XML document with a digital signature</title>
      <link>https://community.qlik.com/t5/Talend-Studio/XML-document-with-a-digital-signature/m-p/2292830#M65867</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;Hi, I need generate an XML document with a digital signature.&lt;BR /&gt;Example of XML document that I must sign and verify your signature:&amp;nbsp;&lt;BR /&gt;&lt;A href="https://www.efactura.dgi.gub.uy/files/ejemplo-de-sobre?es" target="_self" rel="nofollow noopener noreferrer"&gt;https://www.efactura.dgi.gub.uy/files/ejemplo-de-sobre?es&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;I am a programmer (PHP, C++, Python, NodeJs, etc..), but I do not work with the Java language.&lt;BR /&gt;&lt;BR /&gt;How can I generate plugins for the designer of Talend Data Integration&amp;nbsp;could sign my XMl document and the signature is verified. Any recommendation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;&lt;BR /&gt;&lt;EM&gt;Guide translated from Spanish -&lt;/EM&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;EM&gt; &lt;A href="http://www.efactura.dgi.gub.uy/files/guias-en-el-uso-de-xmlencryption-11062014-pdf?es" target="_self" rel="nofollow noopener noreferrer"&gt;http://www.efactura.dgi.gub.uy/files/guias-en-el-uso-de-xmlencryption-11062014-pdf?es&lt;/A&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;Using the XMLEncryption standard (&lt;A href="http://www.w3.org/2001/04/xmlenc" target="_blank" rel="nofollow noopener noreferrer"&gt;http://www.w3.org/2001/04/xmlenc&lt;/A&gt;).&lt;BR /&gt;It should be used as an asymmetric algorithm rsa-pkcs1 (&lt;A href="http://www.w3.org/2001/04/xmlenc#rsa-1_5" target="_blank" rel="nofollow noopener noreferrer"&gt;http://www.w3.org/2001/04/xmlenc#rsa-1_5&lt;/A&gt;) and&lt;BR /&gt;as a symmetric algorithm: 3DES-CBC (&lt;A href="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" target="_blank" rel="nofollow noopener noreferrer"&gt;http://www.w3.org/2001/04/xmlenc#tripledes-cbc&lt;/A&gt;).&lt;BR /&gt;Finally, as a key name (KeyName), CERT_DGI_EFACTURA must be used.&lt;/P&gt; 
&lt;P&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;The public and private keys are generated in the following way:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;1- &lt;SPAN class=""&gt;&lt;SPAN&gt;As a first step, we create the private key pair (cakey.pem) and public key (cacert.pem) of our CA using the RSA algorithm (since DSA only serves to sign).&lt;/SPAN&gt; A bit length (2048) is chosen according to the security that a CA needs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;openssl req -x509 -newkey rsa:4096 -days 3650 -keyout ca\private\cakey.pem -out ca\cacert.pem -config openssl.cfg&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;2- The pair of private keys (clientkey.pem) and CSR (client.cert.req) that will be sent to the CA are created for the Client (CSR stands for Certificate Signing Request or Certificate Signing Request).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;openssl req -newkey rsa:1024 -keyout client\private\clientkey.pem -out client\csr\client.cert.req -config openssl.cfg&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;3- &lt;SPAN class=""&gt;From the Client's CSR (client.cert.req), a signed X509 certificate (version 3) is created with the private key of the CA (clientcert.pem).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;openssl ca -days 3650 -in client\csr\client.cert.req -out client\signed\clientcert.pem -config openssl.cfg&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;4- &lt;SPAN class=""&gt;Finally, the client's private key (clientkey.pem) and its certificate issued by the CA (clientcert.pem) are exported to PKCS # 12 (client.p12).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;openssl pkcs12 -export -out client\client.p12 -inkey client\private\clientkey.pem -in client\signed\clientcert.pem&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;&lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Example implementation in Java.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;import java.security.PrivateKey;
import java.security.PublicKey;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.xml.security.encryption.EncryptedData;
import org.apache.xml.security.encryption.EncryptedKey;
import org.apache.xml.security.encryption.XMLCipher;
import org.apache.xml.security.keys.KeyInfo;
import org.apache.xml.security.utils.EncryptionConstants;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class XMLEncryptionSample {
 static {
  org.apache.xml.security.Init.init();
 }
 private static Document parseFile(String fileName) throws Exception {
  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  dbf.setNamespaceAware(true);
  DocumentBuilder db = dbf.newDocumentBuilder();
  return db.parse(fileName);
 }
 private static SecretKey generateSymmetricKey() throws Exception {
  String jceAlgorithmName = "DESede";
  KeyGenerator keyGenerator = KeyGenerator.getInstance(jceAlgorithmName);
  return keyGenerator.generateKey();
 }
 private static void writeDocToFile(Document doc, String fileName)
 throws Exception {
  FileOutputStream outStream = new FileOutputStream(new File(fileName));
  TransformerFactory factory = TransformerFactory.newInstance();
  Transformer transformer = factory.newTransformer();
  transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
  DOMSource source = new DOMSource(doc);
  transformer.transform(source, new StreamResult(outStream));
  outStream.close();
 }
 public static void encrypt(String source, String target, String ns, String element,
  Key publicKey, String keyName) throws Exception {
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Read XML from file&lt;/SPAN&gt;&lt;/SPAN&gt;
  Document document = parseFile(source);
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Generates symmetric key for 3Des&lt;/SPAN&gt;&lt;/SPAN&gt;
  Key symmetricKey = generateSymmetricKey();
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Initialize cipher to encrypt the symmetric key&lt;/SPAN&gt;&lt;/SPAN&gt;
  XMLCipher keyCipher = XMLCipher.getInstance(XMLCipher.RSA_v1dot5);
  keyCipher.init(XMLCipher.WRAP_MODE, publicKey);
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class="alt-edited"&gt;Encrypts the symmetric key&lt;/SPAN&gt;&lt;/SPAN&gt;
  EncryptedKey encryptedKey = keyCipher
   .encryptKey(document, symmetricKey);
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Specifies the element of the XML document to be encrypted&lt;/SPAN&gt;&lt;/SPAN&gt;
  Element rootElement = document.getDocumentElement();
  Element elementToEncrypt = rootElement;
  if (element != null) {
   elementToEncrypt = (Element) rootElement.getElementsByTagNameNS(
    ns, element).item(0);
   if (elementToEncrypt == null) {
    System.err.println("T&lt;SPAN class="short_text"&gt;&lt;SPAN class="alt-edited"&gt;he element is not found&lt;/SPAN&gt;&lt;/SPAN&gt;: " + element);
   }
  }
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Initialize cipher to encrypt the XML Element&lt;/SPAN&gt;&lt;/SPAN&gt;
  XMLCipher xmlCipher = XMLCipher.getInstance(XMLCipher.TRIPLEDES);
  xmlCipher.init(XMLCipher.ENCRYPT_MODE, symmetricKey);
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Add information from the encryption key&lt;/SPAN&gt;&lt;/SPAN&gt;
  EncryptedData encryptedDataElement = xmlCipher.getEncryptedData();
  KeyInfo innerKeyInfo = new KeyInfo(document);
  innerKeyInfo.addKeyName(keyName);
  encryptedKey.setKeyInfo(innerKeyInfo);
  KeyInfo keyInfo = new KeyInfo(document);
  keyInfo.add(encryptedKey);
  encryptedDataElement.setKeyInfo(keyInfo);
  // Cipher
  xmlCipher.doFinal(document, elementToEncrypt);
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Write the result in the destination file&lt;/SPAN&gt;&lt;/SPAN&gt;
  writeDocToFile(document, target);
 }
 public static void decrypt(String source, String target, Key privateKey)
 throws Exception {
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Read XML from file&lt;/SPAN&gt;&lt;/SPAN&gt;
  Document document = parseFile(source);
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Get the XML Element with encrypted data&lt;/SPAN&gt;&lt;/SPAN&gt;
  String namespaceURI = EncryptionConstants.EncryptionSpecNS;
  String localName = EncryptionConstants._TAG_ENCRYPTEDDATA;
  Element encryptedDataElement = (Element) document
   .getElementsByTagNameNS(namespaceURI, localName).item(0);
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;The symmetric key is decrypted&lt;/SPAN&gt;&lt;/SPAN&gt;
  XMLCipher xmlCipher = XMLCipher.getInstance();
  xmlCipher.init(XMLCipher.DECRYPT_MODE, null);
  xmlCipher.setKEK(privateKey);
  // &lt;SPAN class=""&gt;The encrypted node is replaced with the decrypted information&lt;/SPAN&gt;
  xmlCipher.doFinal(document, encryptedDataElement);
  // &lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;Write the result in the destination file&lt;/SPAN&gt;&lt;/SPAN&gt;
  writeDocToFile(document, target);
 }
}&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;Loading the private and public key from a keystore (# PCKS12) named client.p12 whose alias is client, can be programmed as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;PrivateKey privateKey = null;
PublicKey publicKey = null;
....
....
KeyStore keystore = KeyStore.getInstance("PKCS12");
String p12Password = "secreto";
keystore.load(new FileInputStream("client.p12"), p12Password.toCharArray());
privateKey = (PrivateKey) keystore.getKey("client", p12Password.toCharArray());
publicKey = keystore.getCertificate("client").getPublicKey();&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;Finally, to perform a test, the encrypt / decrypt methods can be used as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;encrypt("Unencrypted.xml", "Encrypted.xml", "http://cfe.dgi.gub.uy", "Compl_Fiscal_Data",
publicKey, "CERT_DGI_EFACTURA");

decrypt("Encrypted.xml", "Decrypted.xml", privateKey);&lt;/PRE&gt; 
&lt;P&gt;&lt;SPAN class=""&gt;&lt;BR /&gt;Excuse me if my English is not understood correctly.&lt;BR /&gt;&lt;BR /&gt;Thank you, I hope that I can integrate this into my project in Talend Data Integration with your help.&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="short_text"&gt;Regards&lt;/SPAN&gt;.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 08:21:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/XML-document-with-a-digital-signature/m-p/2292830#M65867</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-16T08:21:38Z</dc:date>
    </item>
    <item>
      <title>Re: XML document with a digital signature</title>
      <link>https://community.qlik.com/t5/Talend-Studio/XML-document-with-a-digital-signature/m-p/2292831#M65868</link>
      <description>&lt;P&gt;Could someone give me an example, how to implement it.?&amp;nbsp; Thank you very much.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 15:19:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/XML-document-with-a-digital-signature/m-p/2292831#M65868</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-04-25T15:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: XML document with a digital signature</title>
      <link>https://community.qlik.com/t5/Talend-Studio/XML-document-with-a-digital-signature/m-p/2292832#M65869</link>
      <description>&lt;P&gt;Hi Dertin,&lt;/P&gt;&lt;P&gt;I have a similar need, were you able to solve the issue? If Yes, please share the solution&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 17:02:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/XML-document-with-a-digital-signature/m-p/2292832#M65869</guid>
      <dc:creator>tnewbie</dc:creator>
      <dc:date>2020-06-23T17:02:26Z</dc:date>
    </item>
  </channel>
</rss>

