Java org.bouncycastle.operator.OperatorCreationException 代码实例

・6 分钟阅读

以下是展示如何使用org.bouncycastle.operator.OperatorCreationException的最佳示例。 我们使用了代码质量辨别算法从开源项目中提取出了最佳的优秀示例。

实例 1


/**
 * Verify all the SignerInformation objects and optionally their associated counter signatures attached
 * to this CMS SignedData object.
 *
 * @param verifierProvider  a provider of SignerInformationVerifier objects.
 * @param ignoreCounterSignatures if true don't check counter signatures. If false check counter signatures as well.
 * @return true if all verify, false otherwise.
 * @throws CMSException  if an exception occurs during the verification process.
 */
public boolean verifySignatures(SignerInformationVerifierProvider verifierProvider, boolean ignoreCounterSignatures)
    throws CMSException
{
    Collection signers = this.getSignerInfos().getSigners();
    for (Iterator it = signers.iterator(); it.hasNext();)
    {
        SignerInformation signer = (SignerInformation)it.next();
        try
        {
            SignerInformationVerifier verifier = verifierProvider.get(signer.getSID());
            if (!signer.verify(verifier))
            {
                return false;
            }
            if (!ignoreCounterSignatures)
            {
                Collection counterSigners = signer.getCounterSignatures().getSigners();
                for  (Iterator cIt = counterSigners.iterator(); cIt.hasNext();)
                {
                    SignerInformation counterSigner = (SignerInformation)cIt.next();
                    SignerInformationVerifier counterVerifier = verifierProvider.get(signer.getSID());
                    if (!counterSigner.verify(counterVerifier))
                    {
                        return false;
                    }
                }
            }
        }
        catch (OperatorCreationException e)
        {
            throw new CMSException("failure in verifier provider: " + e.getMessage(), e);
        }
    }
    return true;
}
 

实例 2


@Override
public ContentVerifierProvider getContentVerifierProvider(
        final PublicKey publicKey)
throws InvalidKeyException {
    try {
        return KeyUtil.getContentVerifierProvider(publicKey);
    } catch (OperatorCreationException e) {
        throw new InvalidKeyException(e.getMessage(), e);
    }
}
 

实例 3


ContentEncryptor(
    MimeBodyPart content,
    ASN1ObjectIdentifier       encryptionOid,
    int          keySize,
    Provider     provider)
    throws CMSException
{
    _content = content;
    if (keySize == 0)  // use the default
    {
        _encryptor = new JceCMSContentEncryptorBuilder(encryptionOid).setProvider(provider).build();
    }
    else
    {
        _encryptor = new JceCMSContentEncryptorBuilder(encryptionOid, keySize).setProvider(provider).build();
    }
    if (provider != null)
    {
        for (Iterator it = recipients.iterator(); it.hasNext();)
        {
            RecipientInfoGenerator rd = (RecipientInfoGenerator)it.next();
            try
            {
                if (rd instanceof JceKeyTransRecipientInfoGenerator)
                {
                    ((JceKeyTransRecipientInfoGenerator)rd).setProvider(provider);
                }
                else if (rd instanceof JceKEKRecipientInfoGenerator)
                {
                    ((JceKEKRecipientInfoGenerator)rd).setProvider(provider);
                }
            }
            catch (OperatorCreationException e)
            {
                throw new CMSException("cannot create recipient: " + e.getMessage(), e);
            }
        }
    }
}
 

实例 4


public CertificateConfirmationContent build(DigestCalculatorProvider digesterProvider)
    throws CMPException
{
    ASN1EncodableVector v = new ASN1EncodableVector();
    for (int i = 0; i != acceptedCerts.size(); i++)
    {
        X509CertificateHolder certHolder = (X509CertificateHolder)acceptedCerts.get(i);
        BigInteger reqID = (BigInteger)acceptedReqIds.get(i);
        AlgorithmIdentifier digAlg = digestAlgFinder.find(certHolder.toASN1Structure().getSignatureAlgorithm());
        if (digAlg == null)
        {
            throw new CMPException("cannot find algorithm for digest from signature");
        }
        DigestCalculator digester;
        try
        {
            digester = digesterProvider.get(digAlg);
        }
        catch (OperatorCreationException e)
        {
            throw new CMPException("unable to create digest: " + e.getMessage(), e);
        }
        CMPUtil.derEncodeToStream(certHolder.toASN1Structure(), digester.getOutputStream());
        v.add(new CertStatus(digester.getDigest(), reqID));
    }
    return new CertificateConfirmationContent(CertConfirmContent.getInstance(new DERSequence(v)), digestAlgFinder);
}
 
讨论
淘淘あ西西 profile image