title: convert X509 certificate tag value to base64 binary encoding in digital signature cxf wss4j
body: <p>I have used <strong>CXF 3.0.1</strong> for soap implementation and for digital signature I have used <strong>wss4j-WS-security-common 3.0.1</strong> and <strong>CXF-rt-WS-security 3.0.1</strong>. By adding outinterceptor in non-spring settings and along with crypto.merlin properties, I do the digital signature.
  Now according to the output that is obtained, my webservice provider asks for  a <strong>BASE64</strong> binary value of <strong>X509Data</strong> tag.
  To Summarize I want to replace this:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;ds:KeyInfo Id=&quot;...&quot;&gt;
    &lt;wsse:SecurityTokenReference wsu:Id=&quot;...&quot;&gt;
        &lt;ds:X509Data&gt;
          &lt;ds:X509IssuerSerial&gt;
            &lt;ds:X509IssuerName&gt;C=...,O=...,CN=....&lt;/ds:X509IssuerName&gt;
            &lt;ds:X509SerialNumber&gt;70391139840......&lt;/ds:X509SerialNumber&gt;
          &lt;/ds:X509IssuerSerial&gt;
        &lt;/ds:X509Data&gt;
     &lt;/wsse:SecurityTokenReference&gt;
  &lt;/ds:KeyInfo&gt;
  </code></pre>
  <p>With this one:</p>
  <pre class="lang-xml prettyprint-override"><code>    &lt;KeyInfo&gt;
        &lt;X509Data&gt;
          &lt;X509Certificate&gt;MIIE4zCCA8ugAwIBAgI...&lt;/X509Certificate&gt;
        &lt;/X509Data&gt;
      &lt;/KeyInfo&gt;
  </code></pre>
  <p>My current complete output is:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;soap:Envelope xmlns:soap=&quot;http://www.w3.org/2003/05/soap-envelope&quot;&gt;
      &lt;soap:Header&gt;
          &lt;wsse:Security
              xmlns:wsse=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd&quot;
              xmlns:wsu=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&quot;
              soap:mustUnderstand=&quot;true&quot;&gt;
              &lt;ds:Signature xmlns:ds=&quot;http://www.w3.org/2000/09/xmldsig#&quot;
                  Id=&quot;SIG-0ce2ba1e-9382-4b99-918f-40fe35c0bcd6&quot;&gt;
                  &lt;ds:SignedInfo&gt;
                      &lt;ds:CanonicalizationMethod Algorithm=&quot;http://www.w3.org/2001/10/xml-exc-c14n#&quot;&gt;
                          &lt;ec:InclusiveNamespaces xmlns:ec=&quot;http://www.w3.org/2001/10/xml-exc-c14n#&quot;
                              PrefixList=&quot;soap&quot;/&gt;
                      &lt;/ds:CanonicalizationMethod&gt;
                      &lt;ds:SignatureMethod
                          Algorithm=&quot;http://www.w3.org/2001/04/xmldsig-more#rsa-sha256&quot;/&gt;
                      &lt;ds:Reference URI=&quot;#id-f2a96bde-6b41-4283-9fcd-703eca4fd795&quot;&gt;
                          &lt;ds:Transforms&gt;
                              &lt;ds:Transform Algorithm=&quot;http://www.w3.org/2001/10/xml-exc-c14n#&quot;&gt;
                                  &lt;ec:InclusiveNamespaces
                                      xmlns:ec=&quot;http://www.w3.org/2001/10/xml-exc-c14n#&quot;
                                      PrefixList=&quot;&quot;/&gt;
                              &lt;/ds:Transform&gt;
                          &lt;/ds:Transforms&gt;
                          &lt;ds:DigestMethod Algorithm=&quot;http://www.w3.org/2001/04/xmlenc#sha256&quot;/&gt;
                          &lt;ds:DigestValue&gt;nIHemuhLTu4c/drCPaK1is/.....&lt;/ds:DigestValue&gt;
                      &lt;/ds:Reference&gt;
                  &lt;/ds:SignedInfo&gt;
                  &lt;ds:SignatureValue&gt;
                      R3Of2Bf60qeSHFyUf5Op7TCGIwJWnhuyHWTNUxNRNLzye6Qi0YeVXTwb0WF9Nesizs16Y...
                  &lt;/ds:SignatureValue&gt;
                  &lt;ds:KeyInfo Id=&quot;KI-38c8124d-967f-4075-99c3-dca94b7d15e9&quot;&gt;
                      &lt;wsse:SecurityTokenReference wsu:Id=&quot;STR-9defa6fa-794a-40a3-a57d-2bb1335cbfb6&quot;&gt;
                          &lt;ds:X509Data&gt;
                              &lt;ds:X509IssuerSerial&gt;
                                  &lt;ds:X509IssuerName&gt;C=...,O=...,CN=....&lt;/ds:X509IssuerName&gt;
                                  &lt;ds:X509SerialNumber&gt;70391139840......&lt;/ds:X509SerialNumber&gt;
                              &lt;/ds:X509IssuerSerial&gt;
                          &lt;/ds:X509Data&gt;
                      &lt;/wsse:SecurityTokenReference&gt;
                  &lt;/ds:KeyInfo&gt;
              &lt;/ds:Signature&gt;
          &lt;/wsse:Security&gt;
      &lt;/soap:Header&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  <p>output that I want to be shown:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;
      &lt;soap:Envelope xmlns:soap=&quot;http://www.w3.org/2003/05/soap-envelope&quot;&gt;
        &lt;soap:Header&gt;
          &lt;AuthHeader xmlns=&quot;http://tempuri.org/&quot;&gt;
            &lt;UserName&gt;*&lt;/UserName&gt;
            &lt;Password&gt;*&lt;/Password&gt;
          &lt;/AuthHeader&gt;
        &lt;/soap:Header&gt;
        &lt;soap:Body&gt;
          ...
        &lt;/soap:Body&gt;
        &lt;Signature xmlns=&quot;http://www.w3.org/2000/09/xmldsig#&quot;&gt;
          &lt;SignedInfo&gt;
            &lt;CanonicalizationMethod Algorithm=&quot;http://www.w3.org/TR/2001/REC-xml-c14n-20010315&quot; /&gt;
            &lt;SignatureMethod Algorithm=&quot;http://www.w3.org/2001/04/xmldsig-more#rsa-sha256&quot; /&gt;
            &lt;Reference URI=&quot;&quot;&gt;
              &lt;Transforms&gt;
                &lt;Transform Algorithm=&quot;http://www.w3.org/2000/09/xmldsig#enveloped-signature&quot; /&gt;
              &lt;/Transforms&gt;
              &lt;DigestMethod Algorithm=&quot;http://www.w3.org/2001/04/xmlenc#sha256&quot; /&gt;
              &lt;DigestValue&gt;yPt/HXyJyVi1GFFoBb52sTwpaQscONr6QQ2wW....&lt;/DigestValue&gt;
            &lt;/Reference&gt;
          &lt;/SignedInfo&gt;
          &lt;SignatureValue&gt;u+XmtuZRW1pqfnIaExnheNGMgg...&lt;/SignatureValue&gt;
          &lt;KeyInfo&gt;
            &lt;X509Data&gt;
              &lt;X509Certificate&gt;MIIE4zCCA8ugAwIBAgI...&lt;/X509Certificate&gt;
            &lt;/X509Data&gt;
          &lt;/KeyInfo&gt;
        &lt;/Signature&gt;
      &lt;/soap:Envelope&gt;
  </code></pre>
  <p>This is my Java client code:</p>
  <pre class="lang-java prettyprint-override"><code>
   org.apache.cxf.endpoint.Client client =ClientProxy.getClient(ServicesSoap);
   client.getOutInterceptors().add(new SAAJOutInterceptor());
   org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
   Map&lt;String,Object&gt; outProps = new HashMap&lt;String,Object&gt;();
   WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
   cxfEndpoint.getOutInterceptors().add(wssOut);
   outProps.put(WSHandlerConstants.ACTION, &quot;Signature&quot;);
   outProps.put(WSHandlerConstants.USER, &quot;1&quot;);
   outProps.put(WSHandlerConstants.SIG_PROP_FILE,&quot;crypto.properties&quot;);
   outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, 
   ClientPasswordCallback.class.getName());
   outProps.put(WSHandlerConstants.SIG_DIGEST_ALGO, &quot;http://www.w3.org/2001/04/xmlenc#sha256&quot;);
   outProps.put(WSHandlerConstants.MUST_UNDERSTAND, &quot;true&quot;);
   outProps.put(WSHandlerConstants.SIG_ALGO, &quot;http://www.w3.org/2001/04/xmldsig-more#rsa-sha256&quot;);
   outProps.put(WSHandlerConstants.USE_SINGLE_CERTIFICATE, &quot;false&quot;);
   outProps.put(&quot;SecurityToken&quot;, &quot;wsse:Base64Binary&quot;);
  </code></pre>
  <p>crypto.properties:</p>
  <pre><code>org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
  org.apache.ws.security.crypto.merlin.keystore.type=JKS
  org.apache.ws.security.crypto.merlin.file=/home/...
  org.apache.ws.security.crypto.merlin.keystore.alias=1
  org.apache.ws.security.crypto.merlin.keystore.password=...
  </code></pre>