Example usage for org.bouncycastle.cert X509CertificateHolder getSignature

List of usage examples for org.bouncycastle.cert X509CertificateHolder getSignature

Introduction

In this page you can find the example usage for org.bouncycastle.cert X509CertificateHolder getSignature.

Prototype

public byte[] getSignature() 

Source Link

Document

Return the bytes making up the signature associated with this attribute certificate.

Usage

From source file:org.opendaylight.snbi.southplugin.CertificateMgmt.java

License:Open Source License

public static byte[] sign(Certificate cert, KeyPair pair) {
    ContentSigner signGen = null;/* ww  w.j av  a2  s  .  c o  m*/
    X509CertificateHolder certHolder = new X509CertificateHolder(cert);

    try {
        signGen = new JcaContentSignerBuilder(CertManagerConstants.CERT_ALGORITHM.SHA1withRSA.toString())
                .setProvider(CertManagerConstants.BC).build(pair.getPrivate());
    } catch (OperatorCreationException e) {
        e.printStackTrace();
        return null;
    }
    CMSSignedDataGenerator gen = new CMSSignedDataGenerator();

    try {
        gen.addSignerInfoGenerator(
                new SignerInfoGeneratorBuilder(new BcDigestCalculatorProvider()).build(signGen, certHolder));
    } catch (OperatorCreationException e) {
        e.printStackTrace();
        return null;
    }
    return certHolder.getSignature();
}