Example usage for org.bouncycastle.crypto.signers PSSSigner PSSSigner

List of usage examples for org.bouncycastle.crypto.signers PSSSigner PSSSigner

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.signers PSSSigner PSSSigner.

Prototype

public PSSSigner(AsymmetricBlockCipher cipher, Digest contentDigest, Digest mgfDigest, byte[] salt,
            byte trailer) 

Source Link

Usage

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

License:Open Source License

public static PSSSigner createPSSRSASigner(final AlgorithmIdentifier sigAlgId,
        final AsymmetricBlockCipher cipher) throws XiSecurityException {
    ParamUtil.requireNonNull("sigAlgId", sigAlgId);
    if (!PKCSObjectIdentifiers.id_RSASSA_PSS.equals(sigAlgId.getAlgorithm())) {
        throw new XiSecurityException("signature algorithm " + sigAlgId.getAlgorithm() + " is not allowed");
    }/*from ww w .  jav  a 2  s .com*/

    AlgorithmIdentifier digAlgId;
    try {
        digAlgId = AlgorithmUtil.extractDigesetAlgId(sigAlgId);
    } catch (NoSuchAlgorithmException ex) {
        throw new XiSecurityException(ex.getMessage(), ex);
    }

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

    AlgorithmIdentifier mfgDigAlgId = AlgorithmIdentifier
            .getInstance(param.getMaskGenAlgorithm().getParameters());

    Digest dig = getDigest(digAlgId);
    Digest mfgDig = getDigest(mfgDigAlgId);

    int saltSize = param.getSaltLength().intValue();
    int trailerField = param.getTrailerField().intValue();
    AsymmetricBlockCipher tmpCipher = (cipher == null) ? new RSABlindedEngine() : cipher;

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

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  .ja va2  s .  com*/

    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));
}