DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
// SignatureAlgorithm sa = SignatureAlgorithm.getInstance(doc, XMLSignature.ALGO_ID_SIGNATURE_DSA, 120);
SignatureAlgorithm sa = new SignatureAlgorithm(doc,
"http://www.w3.org/2000/09/xmldsig#hmac-sha1",
33);
// SecretKeyFactory skf = SecretKeyFactory.getInstance(sa.getJCEAlgorithmString(), sa.getJCEProviderName());
byte keybytes[] = "01234567890123456789".getBytes();
SecretKey sk = new SecretKeySpec(keybytes, sa.getJCEAlgorithmString());
sa.initSign(sk);
sa.update("sdjhfkjashkjf".getBytes());
byte signatureValue[] = sa.sign();
System.out.println(Base64.encode(signatureValue));
doc.appendChild(sa.getElement());
XMLUtils.outputDOM(doc, System.out);
System.out.println("");
System.out.println("");
javax.crypto.Mac a;
SignatureAlgorithm verifyer =
new SignatureAlgorithm(doc.getDocumentElement(), "file:");
SecretKey pk = new SecretKeySpec("01234567890123456789".getBytes(),
verifyer.getJCEAlgorithmString());
verifyer.initVerify(pk);
verifyer.update("sdjhfkjashkjf".getBytes());
boolean result = verifyer.verify(signatureValue);
if (result) {
System.out.println("It verified");
} else {
System.out.println("It failed");