Example usage for org.bouncycastle.tsp TimeStampToken isSignatureValid

List of usage examples for org.bouncycastle.tsp TimeStampToken isSignatureValid

Introduction

In this page you can find the example usage for org.bouncycastle.tsp TimeStampToken isSignatureValid.

Prototype

public boolean isSignatureValid(SignerInformationVerifier sigVerifier) throws TSPException 

Source Link

Document

Return true if the signature on time stamp token is valid.

Usage

From source file:com.itextpdf.text.pdf.security.CertificateVerification.java

License:Open Source License

/**
 * Verifies a time stamp against a KeyStore.
 * @param ts the time stamp//from   w  w  w.  j ava 2s  .c om
 * @param keystore the <CODE>KeyStore</CODE>
 * @param provider the provider or <CODE>null</CODE> to use the BouncyCastle provider
 * @return <CODE>true</CODE> is a certificate was found
 */
public static boolean verifyTimestampCertificates(TimeStampToken ts, KeyStore keystore, String provider) {
    if (provider == null)
        provider = "BC";
    try {
        for (Enumeration<String> aliases = keystore.aliases(); aliases.hasMoreElements();) {
            try {
                String alias = aliases.nextElement();
                if (!keystore.isCertificateEntry(alias))
                    continue;
                X509Certificate certStoreX509 = (X509Certificate) keystore.getCertificate(alias);
                ts.isSignatureValid(
                        new JcaSimpleSignerInfoVerifierBuilder().setProvider(provider).build(certStoreX509));
                return true;
            } catch (Exception ex) {
            }
        }
    } catch (Exception e) {
    }
    return false;
}