當前位置: 首頁>>代碼示例>>Java>>正文


Java OperatorCreationException類代碼示例

本文整理匯總了Java中org.bouncycastle.operator.OperatorCreationException的典型用法代碼示例。如果您正苦於以下問題:Java OperatorCreationException類的具體用法?Java OperatorCreationException怎麽用?Java OperatorCreationException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


OperatorCreationException類屬於org.bouncycastle.operator包,在下文中一共展示了OperatorCreationException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateSignatureBlock

import org.bouncycastle.operator.OperatorCreationException; //導入依賴的package包/類
private static byte[] generateSignatureBlock(
        SignerConfig signerConfig, byte[] signatureFileBytes)
                throws InvalidKeyException, CertificateEncodingException, SignatureException {
    JcaCertStore certs = new JcaCertStore(signerConfig.certificates);
    X509Certificate signerCert = signerConfig.certificates.get(0);
    String jcaSignatureAlgorithm =
            getJcaSignatureAlgorithm(
                    signerCert.getPublicKey(), signerConfig.signatureDigestAlgorithm);
    try {
        ContentSigner signer =
                new JcaContentSignerBuilder(jcaSignatureAlgorithm)
                .build(signerConfig.privateKey);
        CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
        gen.addSignerInfoGenerator(
                new SignerInfoGeneratorBuilder(
                        new JcaDigestCalculatorProviderBuilder().build(),
                        SignerInfoSignatureAlgorithmFinder.INSTANCE)
                        .setDirectSignature(true)
                        .build(signer, new JcaX509CertificateHolder(signerCert)));
        gen.addCertificates(certs);

        CMSSignedData sigData =
                gen.generate(new CMSProcessableByteArray(signatureFileBytes), false);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (ASN1InputStream asn1 = new ASN1InputStream(sigData.getEncoded())) {
            DEROutputStream dos = new DEROutputStream(out);
            dos.writeObject(asn1.readObject());
        }
        return out.toByteArray();
    } catch (OperatorCreationException | CMSException | IOException e) {
        throw new SignatureException("Failed to generate signature", e);
    }
}
 
開發者ID:Meituan-Dianping,項目名稱:walle,代碼行數:35,代碼來源:V1SchemeSigner.java

示例2: addSelfSignedCertificate

import org.bouncycastle.operator.OperatorCreationException; //導入依賴的package包/類
public void addSelfSignedCertificate(String certificateAlias, String dn, String password) {
	try {
		KeyPair keys = generateKeyPair();

		Calendar start = Calendar.getInstance();
		Calendar expiry = Calendar.getInstance();
		expiry.add(Calendar.YEAR, 1);
		X500Name name = new X500Name(dn);
		X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder(name, BigInteger.ONE,
				start.getTime(), expiry.getTime(), name, SubjectPublicKeyInfo.getInstance(keys.getPublic().getEncoded()));
		ContentSigner signer = new JcaContentSignerBuilder("SHA1WithRSA").setProvider(new BouncyCastleProvider()).build(keys.getPrivate());
		X509CertificateHolder holder = certificateBuilder.build(signer);
		Certificate cert = new JcaX509CertificateConverter().setProvider(new BouncyCastleProvider()).getCertificate(holder);

		Entry entry = new PrivateKeyEntry(keys.getPrivate(), new Certificate[]{ cert });
		keystore.setEntry(certificateAlias, entry, new PasswordProtection(password.toCharArray()));
	} catch (GeneralSecurityException | OperatorCreationException ex) {
		throw new RuntimeException("Unable to generate self-signed certificate", ex);
	}
}
 
開發者ID:xtf-cz,項目名稱:xtf,代碼行數:21,代碼來源:XTFKeyStore.java

示例3: get

import org.bouncycastle.operator.OperatorCreationException; //導入依賴的package包/類
public DigestCalculator get(final AlgorithmIdentifier algorithm)
    throws OperatorCreationException
{
    Digest dig = digestProvider.get(algorithm);

    final DigestOutputStream stream = new DigestOutputStream(dig);

    return new DigestCalculator()
    {
        public AlgorithmIdentifier getAlgorithmIdentifier()
        {
            return algorithm;
        }

        public OutputStream getOutputStream()
        {
            return stream;
        }

        public byte[] getDigest()
        {
            return stream.getDigest();
        }
    };
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:26,代碼來源:BcDigestCalculatorProvider.java

示例4: build

import org.bouncycastle.operator.OperatorCreationException; //導入依賴的package包/類
public ContentVerifierProvider build(final AsymmetricKeyParameter publicKey)
    throws OperatorCreationException
{
    return new ContentVerifierProvider()
    {
        public boolean hasAssociatedCertificate()
        {
            return false;
        }

        public X509CertificateHolder getAssociatedCertificate()
        {
            return null;
        }

        public ContentVerifier get(AlgorithmIdentifier algorithm)
            throws OperatorCreationException
        {
            BcSignerOutputStream stream = createSignatureStream(algorithm, publicKey);

            return new SigVerifier(algorithm, stream);
        }
    };
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:25,代碼來源:BcContentVerifierProviderBuilder.java

示例5: createSignatureStream

import org.bouncycastle.operator.OperatorCreationException; //導入依賴的package包/類
private SignatureOutputStream createSignatureStream(AlgorithmIdentifier algorithm, PublicKey publicKey)
    throws OperatorCreationException
{
    try
    {
        Signature sig = helper.createSignature(algorithm);

        sig.initVerify(publicKey);

        return new SignatureOutputStream(sig);
    }
    catch (GeneralSecurityException e)
    {
        throw new OperatorCreationException("exception on setup: " + e, e);
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:17,代碼來源:JcaContentVerifierProviderBuilder.java

示例6: get

import org.bouncycastle.operator.OperatorCreationException; //導入依賴的package包/類
public PKCS12MacCalculatorBuilder get(final AlgorithmIdentifier algorithmIdentifier)
{
    return new PKCS12MacCalculatorBuilder()
    {
        public MacCalculator build(final char[] password)
            throws OperatorCreationException
        {
            PKCS12PBEParams pbeParams = PKCS12PBEParams.getInstance(algorithmIdentifier.getParameters());

            return PKCS12PBEUtils.createMacCalculator(algorithmIdentifier.getAlgorithm(), digestProvider.get(algorithmIdentifier), pbeParams, password);
        }

        public AlgorithmIdentifier getDigestAlgorithmIdentifier()
        {
            return new AlgorithmIdentifier(algorithmIdentifier.getAlgorithm(), DERNull.INSTANCE);
        }
    };
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:19,代碼來源:BcPKCS12MacCalculatorBuilderProvider.java

示例7: SignerInfoGenerator

import org.bouncycastle.operator.OperatorCreationException; //導入依賴的package包/類
SignerInfoGenerator(
    SignerIdentifier signerIdentifier,
    ContentSigner signer,
    DigestCalculatorProvider digesterProvider,
    CMSSignatureEncryptionAlgorithmFinder sigEncAlgFinder,
    CMSAttributeTableGenerator sAttrGen,
    CMSAttributeTableGenerator unsAttrGen)
    throws OperatorCreationException
{
    this.signerIdentifier = signerIdentifier;
    this.signer = signer;

    if (digesterProvider != null)
    {
        this.digester = digesterProvider.get(digAlgFinder.find(signer.getAlgorithmIdentifier()));
    }
    else
    {
        this.digester = null;
    }

    this.sAttrGen = sAttrGen;
    this.unsAttrGen = unsAttrGen;
    this.sigEncAlgFinder = sigEncAlgFinder;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:26,代碼來源:SignerInfoGenerator.java

示例8: generateServerCertificate

import org.bouncycastle.operator.OperatorCreationException; //導入依賴的package包/類
public static X500PrivateCredential generateServerCertificate(KeyPair caKeyPair) throws NoSuchAlgorithmException, CertificateException, OperatorCreationException, CertIOException {
    X500Name issuerName = new X500Name("CN=bouncrca");
    X500Name subjectName = new X500Name("CN=bouncr");
    BigInteger serial = BigInteger.valueOf(2);
    long t1 = System.currentTimeMillis();
    KeyPairGenerator rsa = KeyPairGenerator.getInstance("RSA");
    rsa.initialize(2048, SecureRandom.getInstance("NativePRNGNonBlocking"));
    KeyPair kp = rsa.generateKeyPair();
    System.out.println(System.currentTimeMillis() - t1);

    X509v3CertificateBuilder builder = new JcaX509v3CertificateBuilder(issuerName, serial, NOT_BEFORE, NOT_AFTER, subjectName, kp.getPublic());
    DERSequence subjectAlternativeNames = new DERSequence(new ASN1Encodable[] {
            new GeneralName(GeneralName.dNSName, "localhost"),
            new GeneralName(GeneralName.dNSName, "127.0.0.1")
    });
    builder.addExtension(Extension.subjectAlternativeName, false, subjectAlternativeNames);
    X509Certificate cert = signCertificate(builder, caKeyPair.getPrivate());

    return new X500PrivateCredential(cert, kp.getPrivate());
}
 
開發者ID:kawasima,項目名稱:bouncr,代碼行數:21,代碼來源:Certificate.java

示例9: createNewStore

import org.bouncycastle.operator.OperatorCreationException; //導入依賴的package包/類
public static boolean createNewStore(String storeType, File storeFile, char[] storePassword, DN dn) {
    if (storeType == null) {
        storeType = "jks";
    }
    try {
        KeyStore ks = KeyStore.getInstance(storeType);
        ks.load(null, null);
        Pair<PrivateKey, X509Certificate> generated = generateKeyAndCertificate("RSA", "SHA1withRSA", dn.validityYears, encodeDN(dn));
        ks.setKeyEntry(dn.alias, generated.getFirst(), dn.password, new Certificate[]{generated.getSecond()});
        FileOutputStream fos = new FileOutputStream(storeFile);
        boolean threw = true;
        try {
            ks.store(fos, storePassword);
            threw = false;
        } finally {
            Closeables.close(fos, threw);
        }
    } catch (KeyStoreException | IOException | NoSuchAlgorithmException | CertificateException | OperatorCreationException e) {
        return false;
    }
    return true;
}
 
開發者ID:NBANDROIDTEAM,項目名稱:NBANDROID-V2,代碼行數:23,代碼來源:ApkUtils.java

示例10: createGenerator

import org.bouncycastle.operator.OperatorCreationException; //導入依賴的package包/類
private SignerInfoGenerator createGenerator(ContentSigner contentSigner, SignerIdentifier sigId)
    throws OperatorCreationException
{
    if (directSignature)
    {
        return new SignerInfoGenerator(sigId, contentSigner, digestProvider, sigEncAlgFinder, true);
    }

    if (signedGen != null || unsignedGen != null)
    {
        if (signedGen == null)
        {
            signedGen = new DefaultSignedAttributeTableGenerator();
        }

        return new SignerInfoGenerator(sigId, contentSigner, digestProvider, sigEncAlgFinder, signedGen, unsignedGen);
    }
    
    return new SignerInfoGenerator(sigId, contentSigner, digestProvider, sigEncAlgFinder);
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:21,代碼來源:SignerInfoGeneratorBuilder.java

示例11: getMessageImprintDigestCalculator

import org.bouncycastle.operator.OperatorCreationException; //導入依賴的package包/類
DigestCalculator getMessageImprintDigestCalculator(DigestCalculatorProvider calculatorProvider)
    throws OperatorCreationException
{
    TimeStampToken token;

    try
    {
        token = this.getTimeStampToken(timeStamps[0]);

        TimeStampTokenInfo info = token.getTimeStampInfo();
        ASN1ObjectIdentifier algOID = info.getMessageImprintAlgOID();

        DigestCalculator calc = calculatorProvider.get(new AlgorithmIdentifier(algOID));

        initialiseMessageImprintDigestCalculator(calc);

        return calc;
    }
    catch (CMSException e)
    {
        throw new OperatorCreationException("unable to extract algorithm ID: " + e.getMessage(), e);
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:24,代碼來源:TimeStampDataUtil.java

示例12: generate

import org.bouncycastle.operator.OperatorCreationException; //導入依賴的package包/類
public PemObject generate()
    throws PemGenerationException
{
    try
    {
        if (encryptorBuilder != null)
        {
            outputEncryptor = encryptorBuilder.build();
        }
    }
    catch (OperatorCreationException e)
    {
        throw new PemGenerationException("unable to create operator: " + e.getMessage(), e);
    }

    if (outputEncryptor != null)
    {
        return generate(key, outputEncryptor);
    }
    else
    {
        return generate(key, null);
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:25,代碼來源:PKCS8Generator.java

示例13: createSigner

import org.bouncycastle.operator.OperatorCreationException; //導入依賴的package包/類
protected Signer createSigner(AlgorithmIdentifier sigAlgId, AlgorithmIdentifier digAlgId)
        throws OperatorCreationException {
    if (!AlgorithmUtil.isRSASigAlgId(sigAlgId)) {
        throw new OperatorCreationException(
                "the given algorithm is not a valid RSA signature algirthm '"
                + sigAlgId.getAlgorithm().getId() + "'");
    }

    if (!PKCSObjectIdentifiers.id_RSASSA_PSS.equals(sigAlgId.getAlgorithm())) {
        Digest dig = digestProvider.get(digAlgId);
        return new RSADigestSigner(dig);
    }

    try {
        return SignerUtil.createPSSRSASigner(sigAlgId);
    } catch (XiSecurityException ex) {
        throw new OperatorCreationException(ex.getMessage(), ex);
    }
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:20,代碼來源:SoftTokenContentSignerBuilder.java

示例14: addSignedCertificate

import org.bouncycastle.operator.OperatorCreationException; //導入依賴的package包/類
public void addSignedCertificate(final XTFKeyStore signerKeyStore, final String signerAlias, final String signerPassword, final String dn, final String certificateAlias, final String password) {
	try {
		final X509Certificate caCert = (X509Certificate) signerKeyStore.keystore.getCertificate(signerAlias);
		final PrivateKey caKey = (PrivateKey) signerKeyStore.keystore.getKey(signerAlias, signerPassword.toCharArray());
		final Calendar start = Calendar.getInstance();
		final Calendar expiry = Calendar.getInstance();
		expiry.add(Calendar.YEAR, 1);
		final KeyPair keyPair = generateKeyPair();
		final X500Name certName = new X500Name(dn);
		final X500Name issuerName = new X500Name(caCert.getSubjectDN().getName());
		X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder(
				issuerName,
				BigInteger.valueOf(System.nanoTime()),
				start.getTime(),
				expiry.getTime(),
				certName,
				SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded()));
		final JcaX509ExtensionUtils u = new JcaX509ExtensionUtils();
		certificateBuilder.addExtension(Extension.authorityKeyIdentifier, false,
				u.createAuthorityKeyIdentifier(caCert));
		certificateBuilder.addExtension(Extension.subjectKeyIdentifier, false,
				u.createSubjectKeyIdentifier(keyPair.getPublic()));
		ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSA").setProvider(new BouncyCastleProvider()).build(caKey);
		X509CertificateHolder holder = certificateBuilder.build(signer);
		Certificate cert = new JcaX509CertificateConverter().setProvider(new BouncyCastleProvider()).getCertificate(holder);

		Entry entry = new PrivateKeyEntry(keyPair.getPrivate(), new Certificate[] {cert, caCert});
		keystore.setEntry(certificateAlias, entry, new PasswordProtection(password.toCharArray()));
	} catch (GeneralSecurityException | OperatorCreationException | CertIOException ex) {
		throw new RuntimeException("Unable to generate signed certificate", ex);
	}
}
 
開發者ID:xtf-cz,項目名稱:xtf,代碼行數:33,代碼來源:XTFKeyStore.java

示例15: build

import org.bouncycastle.operator.OperatorCreationException; //導入依賴的package包/類
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);
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:35,代碼來源:CertificateConfirmationContentBuilder.java


注:本文中的org.bouncycastle.operator.OperatorCreationException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。