public void verifySignature(String message,String signature,String algorithmUri) throws IllegalStateException, WebssoClientException {
  log.debug("Verify signature.");
  Validate.notNull(message,"signed content");
  Validate.notNull(signature,"signature");
  Validate.notNull(algorithmUri,"algorithm uri");
  Validate.notNull(getCertificate(),"signing certificate");
  boolean verifies=false;
  String decodedAlgorithmUri=null;
  byte[] decodedSignature=null;
  try {
    decodedAlgorithmUri=URLDecoder.decode(algorithmUri,"UTF-8");
    log.debug("Signature algorithm uri {}",decodedAlgorithmUri);
    decodedSignature=Base64.decode(URLDecoder.decode(signature,"UTF-8"));
  }
 catch (  UnsupportedEncodingException e) {
    throw new WebssoClientException("Could not decode algorithm uri or signature",e);
  }
  try {
    SignatureAlgorithm algo=SignatureAlgorithm.getSignatureAlgorithmForURI(decodedAlgorithmUri);
    Signature sig=Signature.getInstance(algo.getAlgorithmName());
    X509Certificate cert=getCertificate();
    sig.initVerify(cert.getPublicKey());
    sig.update(message.getBytes("UTF-8"));
    verifies=sig.verify(decodedSignature);
    log.debug("signature verifies: " + verifies);
  }
 catch (  Exception e) {
    log.error("Caught exception ",e);
    throw new IllegalStateException(e);
  }
  if (!verifies) {
    throw new IllegalStateException("Signature verification failed.");
  }
}

public void verifySignature ( String message , String signature , String algorithmUri ) throws IllegalStateException , WebssoClientException { log . debug ( "Verify signature." ) ; Validate . notNull ( message , "signed content" ) ; Validate . notNull ( signature , "signature" ) ; Validate . notNull ( algorithmUri , "algorithm uri" ) ; Validate . notNull ( getCertificate ( ) , "signing certificate" ) ; boolean verifies = false ; String decodedAlgorithmUri = null ; byte [ ] decodedSignature = null ; try { decodedAlgorithmUri = URLDecoder . decode ( algorithmUri , "UTF-8" ) ; log . debug ( "Signature algorithm uri {}" , decodedAlgorithmUri ) ; decodedSignature = Base64 . decode ( URLDecoder . decode ( signature , "UTF-8" ) ) ; } catch ( UnsupportedEncodingException e ) { throw new WebssoClientException ( "Could not decode algorithm uri or signature" , e ) ; } try { SignatureAlgorithm algo = SignatureAlgorithm . getSignatureAlgorithmForURI ( decodedAlgorithmUri ) ; Signature sig = Signature . getInstance ( algo . getAlgorithmName ( ) ) ; X509Certificate cert = getCertificate ( ) ; sig . initVerify ( cert . getPublicKey ( ) ) ; sig . update ( message . getBytes ( "UTF-8" ) ) ; verifies = sig . verify ( decodedSignature ) ; log . debug ( "signature verifies: " + verifies ) ; } catch ( Exception e ) { log . error ( "Caught exception " , e ) ; throw new IllegalStateException ( e ) ; } if ( ! verifies ) { throw new IllegalStateException ( "Signature verification failed." ) ; } }
verifies signature of the message with a known public key and signature algorithm . throws on error .
