public boolean verifyHMACSignature(Key key,SignedInfo si,byte [] signatureValue,
int outputLength) throws InvalidKeyException, SignatureException{
if (key == null || si == null || signatureValue == null) {
throw new NullPointerException("key, signedinfo or signature data can't be null");
}
HmacSHA1 hmac = new HmacSHA1();
hmac.init(key, outputLength);
MacOutputStream mos = new MacOutputStream(hmac);
if(si.getSignedInfo() != null){
XMLStreamReaderEx signedInfo = (XMLStreamReaderEx) si.getSignedInfo();
if(_exc14nSBCanonicalizer == null){
_exc14nSBCanonicalizer = new EXC14nStAXReaderBasedCanonicalizer();
}
NamespaceContextEx nsContext = signedInfo.getNamespaceContext();
Iterator<NamespaceContextEx.Binding> itr = nsContext.iterator();
ArrayList list = new ArrayList();
while(itr.hasNext()){
NamespaceContextEx.Binding binding = itr.next();
AttributeNS ans = new AttributeNS();
ans.setPrefix( binding.getPrefix());
ans.setUri(binding.getNamespaceURI());
list.add(ans);
}
_exc14nSBCanonicalizer.addParentNamespaces(list);
_exc14nSBCanonicalizer.addParentNamespaces(list);
try {
_exc14nSBCanonicalizer.canonicalize(signedInfo,mos,null);
} catch (XMLStreamException ex) {
logger.log(Level.SEVERE, LogStringsMessages.WSS_1724_SIGTYPE_VERIFICATION_FAILED("HMAC_SHA1"));
throw new SignatureException(LogStringsMessages.WSS_1724_SIGTYPE_VERIFICATION_FAILED("HMAC_SHA1"),ex);
} catch (IOException ex) {
logger.log(Level.SEVERE, LogStringsMessages.WSS_1724_SIGTYPE_VERIFICATION_FAILED("HMAC_SHA1"));
throw new SignatureException(LogStringsMessages.WSS_1724_SIGTYPE_VERIFICATION_FAILED("HMAC_SHA1"),ex);
}
}else{
mos.write(si.getCanonicalizedSI());
}
return hmac.verify(signatureValue);
}