Search in sources :

Example 1 with JcaX509CertificateHolder

use of com.github.zhenwei.pkix.cert.jcajce.JcaX509CertificateHolder in project LinLong-Java by zhenwei1108.

the class JcaSimpleSignerInfoGeneratorBuilder method build.

public SignerInfoGenerator build(String algorithmName, PrivateKey privateKey, X509Certificate certificate) throws OperatorCreationException, CertificateEncodingException {
    privateKey = CMSUtils.cleanPrivateKey(privateKey);
    ContentSigner contentSigner = helper.createContentSigner(algorithmName, privateKey);
    return configureAndBuild().build(contentSigner, new JcaX509CertificateHolder(certificate));
}
Also used : ContentSigner(com.github.zhenwei.pkix.operator.ContentSigner) JcaX509CertificateHolder(com.github.zhenwei.pkix.cert.jcajce.JcaX509CertificateHolder)

Example 2 with JcaX509CertificateHolder

use of com.github.zhenwei.pkix.cert.jcajce.JcaX509CertificateHolder in project LinLong-Java by zhenwei1108.

the class JcaContentVerifierProviderBuilder method build.

public ContentVerifierProvider build(final X509Certificate certificate) throws OperatorCreationException {
    final X509CertificateHolder certHolder;
    try {
        certHolder = new JcaX509CertificateHolder(certificate);
    } catch (CertificateEncodingException e) {
        throw new OperatorCreationException("cannot process certificate: " + e.getMessage(), e);
    }
    return new ContentVerifierProvider() {

        public boolean hasAssociatedCertificate() {
            return true;
        }

        public X509CertificateHolder getAssociatedCertificate() {
            return certHolder;
        }

        public ContentVerifier get(AlgorithmIdentifier algorithm) throws OperatorCreationException {
            if (algorithm.getAlgorithm().equals(MiscObjectIdentifiers.id_alg_composite)) {
                return createCompositeVerifier(algorithm, certificate.getPublicKey());
            } else {
                Signature sig;
                try {
                    sig = helper.createSignature(algorithm);
                    sig.initVerify(certificate.getPublicKey());
                } catch (GeneralSecurityException e) {
                    throw new OperatorCreationException("exception on setup: " + e, e);
                }
                Signature rawSig = createRawSig(algorithm, certificate.getPublicKey());
                if (rawSig != null) {
                    return new RawSigVerifier(algorithm, sig, rawSig);
                } else {
                    return new SigVerifier(algorithm, sig);
                }
            }
        }
    };
}
Also used : X509CertificateHolder(com.github.zhenwei.pkix.cert.X509CertificateHolder) JcaX509CertificateHolder(com.github.zhenwei.pkix.cert.jcajce.JcaX509CertificateHolder) Signature(java.security.Signature) GeneralSecurityException(java.security.GeneralSecurityException) CertificateEncodingException(java.security.cert.CertificateEncodingException) OperatorCreationException(com.github.zhenwei.pkix.operator.OperatorCreationException) JcaX509CertificateHolder(com.github.zhenwei.pkix.cert.jcajce.JcaX509CertificateHolder) ContentVerifierProvider(com.github.zhenwei.pkix.operator.ContentVerifierProvider) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)

Aggregations

JcaX509CertificateHolder (com.github.zhenwei.pkix.cert.jcajce.JcaX509CertificateHolder)2 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)1 X509CertificateHolder (com.github.zhenwei.pkix.cert.X509CertificateHolder)1 ContentSigner (com.github.zhenwei.pkix.operator.ContentSigner)1 ContentVerifierProvider (com.github.zhenwei.pkix.operator.ContentVerifierProvider)1 OperatorCreationException (com.github.zhenwei.pkix.operator.OperatorCreationException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 Signature (java.security.Signature)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1