Example usage for org.bouncycastle.operator.bc BcDigestCalculatorProvider get

List of usage examples for org.bouncycastle.operator.bc BcDigestCalculatorProvider get

Introduction

In this page you can find the example usage for org.bouncycastle.operator.bc BcDigestCalculatorProvider get.

Prototype

public DigestCalculator get(final AlgorithmIdentifier algorithm) throws OperatorCreationException 

Source Link

Usage

From source file:com.tremolosecurity.proxy.auth.ssl.OCSP.java

License:Apache License

private OCSPReq generateOcspRequest(X509Certificate issuerCert, BigInteger serialNumber)
        throws OCSPException, CertificateEncodingException, OperatorCreationException, IOException {

    BcDigestCalculatorProvider util = new BcDigestCalculatorProvider();

    // Generate the id for the certificate we are looking for
    CertificateID id = new CertificateID(util.get(CertificateID.HASH_SHA1),
            new X509CertificateHolder(issuerCert.getEncoded()), serialNumber);
    OCSPReqBuilder ocspGen = new OCSPReqBuilder();

    ocspGen.addRequest(id);//from   w w w. j a  v a2  s .co  m

    BigInteger nonce = BigInteger.valueOf(System.currentTimeMillis());
    Extension ext = new Extension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce, true,
            new DEROctetString(nonce.toByteArray()));
    ocspGen.setRequestExtensions(new Extensions(new Extension[] { ext }));

    return ocspGen.build();
}

From source file:org.jruby.ext.openssl.OCSPCertificateId.java

License:Common Public License

private IRubyObject initializeImpl(final ThreadContext context, BigInteger serial, IRubyObject issuerCert,
        IRubyObject digest) {//from w  w  w . j a  v a  2  s . c  om
    Ruby runtime = context.getRuntime();

    Digest rubyDigest = (Digest) digest;
    ASN1ObjectIdentifier oid = ASN1.sym2Oid(runtime, rubyDigest.getName().toLowerCase());
    AlgorithmIdentifier bcAlgId = new AlgorithmIdentifier(oid);
    BcDigestCalculatorProvider calculatorProvider = new BcDigestCalculatorProvider();
    DigestCalculator calc;
    try {
        calc = calculatorProvider.get(bcAlgId);
    } catch (OperatorCreationException e) {
        throw newOCSPError(runtime, e);
    }

    X509Cert rubyCert = (X509Cert) issuerCert;

    try {
        this.bcCertId = new CertificateID(calc, new X509CertificateHolder(rubyCert.getAuxCert().getEncoded()),
                serial).toASN1Primitive();
    } catch (Exception e) {
        throw newOCSPError(runtime, e);
    }

    return this;
}