private Document<Element> signDocument(Abdera abdera, Document<Element> doc) throws SecurityException {
AbderaSecurity security = new AbderaSecurity(abdera);
if (signingKey == null || cert == null)
return doc; // pass through
Signature sig = security.getSignature();
SignatureOptions options = sig.getDefaultSignatureOptions();
options.setCertificate(cert);
options.setSigningKey(signingKey);
if (algorithm != null)
options.setSigningAlgorithm(algorithm);
Element element = doc.getRoot();
element = sig.sign(element, options);
return element.getDocument();
}