certificateAlias);
assertNotNull(signingKey);
assertNotNull(cert);
// Create the entry to sign
Abdera abdera = new Abdera();
AbderaSecurity absec = new AbderaSecurity(abdera);
Factory factory = abdera.getFactory();
Entry entry = factory.newEntry();
entry.setId("http://example.org/foo/entry");
entry.setUpdated(new java.util.Date());
entry.setTitle("This is an entry");
entry.setContentAsXhtml("This <b>is</b> <i>markup</i>");
entry.addAuthor("James");
entry.addLink("http://www.example.org");
// Prepare the digital signature options
Signature sig = absec.getSignature();
SignatureOptions options = sig.getDefaultSignatureOptions();
options.setCertificate(cert);
options.setSigningKey(signingKey);
// Sign the entry
entry = sig.sign(entry, options);
assertNotNull(
entry.getFirstChild(
new QName(
"http://www.w3.org/2000/09/xmldsig#",
"Signature")));
X509Certificate[] certs = sig.getValidSignatureCertificates(entry, options);
assertNotNull(certs);
assertEquals(certs.length, 1);
assertEquals(certs[0].getSubjectDN().getName(), "CN=James M Snell, OU=WebAhead, O=IBM, L=Hanford, ST=California, C=US");
// Check the round trip
ByteArrayOutputStream out = new ByteArrayOutputStream();
entry.writeTo(out); // do not use the pretty writer, it will break the signature
ByteArrayInputStream bais = new ByteArrayInputStream(out.toByteArray());
Document<Entry> entry_doc = abdera.getParser().parse(bais);
entry = entry_doc.getRoot();
assertTrue(sig.verify(entry, null)); // the signature better still be valid
entry.setTitle("Change the title");