title: Is there an easier way to sign an XML document in Java?
body: <p>I'm trying to <a href="http://www.w3.org/TR/xmldsig-core/" rel="noreferrer">digitally sign an XML document</a> using Java. I've got an implementation working with some references I've found that use various implementations in the <a href="http://java.sun.com/javase/6/docs/api/javax/xml/crypto/dsig/package-summary.html" rel="noreferrer"><code>javax.xml.crypto.dsig</code></a> package.</p>
  
  <p>However, my current implementation is like <a href="http://java.sun.com/developer/technicalArticles/xml/dig_signatures/" rel="noreferrer">many</a> of the <a href="http://www.java-tips.org/java-ee-tips/xml-digital-signature-api/using-the-java-xml-digital-signatur-2.html" rel="noreferrer">examples</a> I've looked at - it's rather verbose and involves using no less than 23 different API classes from the <code>java.xml.crypto.dsig</code>, <code>javax.xml.transform</code>, and <code>java.security</code> packages, among others. It feels like I've entered <a href="http://discuss.joelonsoftware.com/default.asp?joel.3.219431.12" rel="noreferrer">factory factory factory</a> land, and it took me several hours just to figure out what was going on.</p>
  
  <p>My question is, <strong>is there an easier way to do this?</strong> If I've got public/private key files and I want to add a <code>&lt;Signature/&gt;</code> to an XML document, is there a library out there that just lets me call something like:</p>
  
  <pre><code>OutputStream signFile(InputStream xmlFile, File privateKey)
  </code></pre>
  
  <p>...without all of the XMLSignatureFactory/CanonicalizationMethod/DOMSignContext craziness? </p>
  
  <p>I'm not very well-versed in cryptography, and the Java-provided API seems rather daunting for developers like myself trying to become familiar with digital signing. If all of this is necessary or there's currently no friendlier API out there, that's fine and I'm willing to accept that as an answer. I'd just like to know if I'm unnecessarily taking the hard road here.</p>