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

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

Introduction

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

Prototype

ExtendedDigest get(AlgorithmIdentifier digestAlgorithmIdentifier) throws OperatorCreationException;

Source Link

Usage

From source file:org.xipki.security.SignerUtil.java

License:Open Source License

static public PSSSigner createPSSRSASigner(final AlgorithmIdentifier sigAlgId, AsymmetricBlockCipher cipher)
        throws OperatorCreationException {
    if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(sigAlgId.getAlgorithm()) == false) {
        throw new OperatorCreationException(
                "signature algorithm " + sigAlgId.getAlgorithm() + " is not allowed");
    }/*from  w  w  w .  j  av  a2s. co m*/

    BcDigestProvider digestProvider = BcDefaultDigestProvider.INSTANCE;
    AlgorithmIdentifier digAlgId;
    try {
        digAlgId = AlgorithmUtil.extractDigesetAlgorithmIdentifier(sigAlgId);
    } catch (NoSuchAlgorithmException e) {
        throw new OperatorCreationException(e.getMessage(), e);
    }
    Digest dig = digestProvider.get(digAlgId);
    if (cipher == null) {
        cipher = new RSABlindedEngine();
    }

    RSASSAPSSparams param = RSASSAPSSparams.getInstance(sigAlgId.getParameters());

    AlgorithmIdentifier mfgDigAlgId = AlgorithmIdentifier
            .getInstance(param.getMaskGenAlgorithm().getParameters());
    Digest mfgDig = digestProvider.get(mfgDigAlgId);

    int saltSize = param.getSaltLength().intValue();
    int trailerField = param.getTrailerField().intValue();

    return new PSSSigner(cipher, dig, mfgDig, saltSize, getTrailer(trailerField));
}