title: Java 1.7 com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException: Cannot resolve element with ID data
body: <p>I have done some xml signing in Java 1.6 but when I run the same example in Java 1.7 I get this kind of exception:</p>
  
  <pre><code> javax.xml.crypto.dsig.XMLSignatureException:
   javax.xml.crypto.URIReferenceException:
   com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException:
   Cannot resolve element with ID data
  </code></pre>
  
  <p>my xml:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fu="http://www.fu.gov.si/" xmlns:xd="http://www.w3.org/2000/09/xmldsig#"&gt;
      &lt;soapenv:Body&gt;
          &lt;fu:BusinessPremiseRequest Id="data"&gt;
              &lt;fu:Header&gt;
                  &lt;fu:MessageID&gt;24A4BACB-2355-0564-E053-AB02010AD740&lt;/fu:MessageID&gt;
                  &lt;fu:DateTime&gt;2015-11-16T09:22:58&lt;/fu:DateTime&gt;
              &lt;/fu:Header&gt;
          &lt;/fu:BusinessPremiseRequest&gt;
      &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  
  
  <p>and this is my source code:</p>
  
  <pre><code>DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
  dbFactory.setNamespaceAware(true);
  Document doc = (Document) dbFactory.newDocumentBuilder().parse(new ByteArrayInputStream(xml.getBytes()));
  
  
  NodeList nl = doc.getElementsByTagName("fu:BusinessPremiseRequest");
  Node node = nl.item(0);
  
  KeyStore p12 = KeyStore.getInstance("pkcs12");
  p12.load(new FileInputStream("c:/cert/testfurs.p12"), "Geslo123#".toCharArray());
  Enumeration e = p12.aliases();
  String alias = (String) e.nextElement();
  System.out.println("Alias certifikata:" + alias);
  Key privateKey = p12.getKey(alias, "Geslo123#".toCharArray());
  
  KeyStore.PrivateKeyEntry keyEntry
          = (KeyStore.PrivateKeyEntry) p12.getEntry(alias, new KeyStore.PasswordProtection("Geslo123#".toCharArray()));
  
  X509Certificate cert = (X509Certificate) keyEntry.getCertificate();
  
  PublicKey publicKey = cert.getPublicKey();
  
  final XMLSignatureFactory sigFactory = XMLSignatureFactory.getInstance("DOM");
  // Create a Reference to the enveloped document
  Reference ref = sigFactory.newReference("#data",
          sigFactory.newDigestMethod(DigestMethod.SHA256, null),
          Collections.singletonList(sigFactory.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null)),
          null,
          null);
  
  
  SignedInfo si = sigFactory.newSignedInfo(sigFactory.newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec) null), sigFactory.newSignatureMethod("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256", null), Collections.singletonList(ref));
  
  // Create a KeyValue containing the RSA PublicKey 
  KeyInfoFactory keyInfoFactory = sigFactory.getKeyInfoFactory();
  X509IssuerSerial x509IssuerSerial = keyInfoFactory.newX509IssuerSerial(cert.getSubjectX500Principal().getName(), cert.getSerialNumber());
  
  List x509Content = new ArrayList();
  
  x509Content.add(cert.getSubjectX500Principal().getName());
  x509Content.add(x509IssuerSerial);
  
  KeyValue keyValue = keyInfoFactory.newKeyValue(publicKey);
  X509Data xd = keyInfoFactory.newX509Data(x509Content);
  
  // Create a KeyInfo and add the KeyValue to it
  KeyInfo keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(xd));
  
  // Create a DOMSignContext and specify the RSA PrivateKey and
  // location of the resulting XMLSignature's parent element
  DOMSignContext dsc = new DOMSignContext(
          privateKey,
          node
  );
  </code></pre>