当前位置: 首页>>代码示例>>Java>>正文


Java PKCS10CertificationRequest.getEncoded方法代码示例

本文整理汇总了Java中org.bouncycastle.pkcs.PKCS10CertificationRequest.getEncoded方法的典型用法代码示例。如果您正苦于以下问题:Java PKCS10CertificationRequest.getEncoded方法的具体用法?Java PKCS10CertificationRequest.getEncoded怎么用?Java PKCS10CertificationRequest.getEncoded使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.pkcs.PKCS10CertificationRequest的用法示例。


在下文中一共展示了PKCS10CertificationRequest.getEncoded方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: certificationRequestToPEM

import org.bouncycastle.pkcs.PKCS10CertificationRequest; //导入方法依赖的package包/类
/**
 * certificationRequestToPEM - Convert a PKCS10CertificationRequest to PEM
 * format.
 *
 * @param csr The Certificate to convert
 * @return An equivalent PEM format certificate.
 * @throws IOException
 */

private String certificationRequestToPEM(PKCS10CertificationRequest csr) throws IOException {
    PemObject pemCSR = new PemObject("CERTIFICATE REQUEST", csr.getEncoded());

    StringWriter str = new StringWriter();
    JcaPEMWriter pemWriter = new JcaPEMWriter(str);
    pemWriter.writeObject(pemCSR);
    pemWriter.close();
    str.close();
    return str.toString();
}
 
开发者ID:hyperledger,项目名称:fabric-sdk-java,代码行数:20,代码来源:CryptoPrimitives.java

示例2: generateX509CSR

import org.bouncycastle.pkcs.PKCS10CertificationRequest; //导入方法依赖的package包/类
public static String generateX509CSR(PrivateKey privateKey, PublicKey publicKey,
        String x500Principal, GeneralName[] sanArray) throws OperatorCreationException, IOException {

    // Create Distinguished Name

    X500Principal subject = new X500Principal(x500Principal);

    // Create ContentSigner

    JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder(Crypto.RSA_SHA256);
    ContentSigner signer = csBuilder.build(privateKey);

    // Create the CSR

    PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder(
            subject, publicKey);

    // Add SubjectAlternativeNames (SAN) if specified

    if (sanArray != null) {
        ExtensionsGenerator extGen = new ExtensionsGenerator();
        GeneralNames subjectAltNames = new GeneralNames(sanArray);
        extGen.addExtension(Extension.subjectAlternativeName, false, subjectAltNames);
        p10Builder.addAttribute(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest, extGen.generate());
    }
    
    PKCS10CertificationRequest csr = p10Builder.build(signer);

    // write to openssl PEM format

    PemObject pemObject = new PemObject("CERTIFICATE REQUEST", csr.getEncoded());
    StringWriter strWriter;
    try (JcaPEMWriter pemWriter = new JcaPEMWriter(strWriter = new StringWriter())) {
        pemWriter.writeObject(pemObject);
    }
    return strWriter.toString();
}
 
开发者ID:yahoo,项目名称:athenz,代码行数:38,代码来源:Crypto.java

示例3: generateCSR

import org.bouncycastle.pkcs.PKCS10CertificationRequest; //导入方法依赖的package包/类
public byte[] generateCSR(X500Name name) throws OperatorCreationException, IOException {
	PKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(name, this.publicKey);
	JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256withRSA");
	ContentSigner signer = csBuilder.build(this.privateKey);
	PKCS10CertificationRequest csr = csrBuilder.build(signer);
	return csr.getEncoded();
}
 
开发者ID:e-Contract,项目名称:mycarenet,代码行数:8,代码来源:CertRASession.java

示例4: decode

import org.bouncycastle.pkcs.PKCS10CertificationRequest; //导入方法依赖的package包/类
@Override
public CertificationRequest decode(InputStream in) throws IOException {
    PKCS10CertificationRequest csr = new PKCS10CertificationRequest(IOUtils.toByteArray(in));
    if (csr == null) {
        throw new IOException("Failed to parse CSR");
    }
    final byte[] bytes = csr.getEncoded();

    return new CertificationRequest() {
        @Override
        public byte[] getBytes() {
            return bytes;
        }
    };
}
 
开发者ID:jscep,项目名称:jester,代码行数:16,代码来源:BouncyCastleCertificateRequestDecoder.java

示例5: rsaCreationTest

import org.bouncycastle.pkcs.PKCS10CertificationRequest; //导入方法依赖的package包/类
private void rsaCreationTest()
    throws Exception
{
    //
    // a lightweight key pair.
    //
    RSAKeyParameters lwPubKey = new RSAKeyParameters(
        false,
        new BigInteger("b4a7e46170574f16a97082b22be58b6a2a629798419be12872a4bdba626cfae9900f76abfb12139dce5de56564fab2b6543165a040c606887420e33d91ed7ed7", 16),
        new BigInteger("11", 16));

    RSAPrivateCrtKeyParameters lwPrivKey = new RSAPrivateCrtKeyParameters(
        new BigInteger("b4a7e46170574f16a97082b22be58b6a2a629798419be12872a4bdba626cfae9900f76abfb12139dce5de56564fab2b6543165a040c606887420e33d91ed7ed7", 16),
        new BigInteger("11", 16),
        new BigInteger("9f66f6b05410cd503b2709e88115d55daced94d1a34d4e32bf824d0dde6028ae79c5f07b580f5dce240d7111f7ddb130a7945cd7d957d1920994da389f490c89", 16),
        new BigInteger("c0a0758cdf14256f78d4708c86becdead1b50ad4ad6c5c703e2168fbf37884cb", 16),
        new BigInteger("f01734d7960ea60070f1b06f2bb81bfac48ff192ae18451d5e56c734a5aab8a5", 16),
        new BigInteger("b54bb9edff22051d9ee60f9351a48591b6500a319429c069a3e335a1d6171391", 16),
        new BigInteger("d3d83daf2a0cecd3367ae6f8ae1aeb82e9ac2f816c6fc483533d8297dd7884cd", 16),
        new BigInteger("b8f52fc6f38593dabb661d3f50f8897f8106eee68b1bce78a95b132b4e5b5d19", 16));

    //
    // distinguished name table.
    //
    X500NameBuilder builder = new X500NameBuilder(BCStyle.INSTANCE);

    builder.addRDN(BCStyle.C, "AU");
    builder.addRDN(BCStyle.O, "The Legion of the Bouncy Castle");
    builder.addRDN(BCStyle.L, "Melbourne");
    builder.addRDN(BCStyle.ST, "Victoria");
    builder.addRDN(BCStyle.E, "[email protected]");

    //
    // extensions
    //

    //
    // create the certificate - version 3 - without extensions
    //
    AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA256WithRSAEncryption");
    AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);

    ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build(lwPrivKey);
    SubjectPublicKeyInfo pubInfo = new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPublicKey(lwPubKey.getModulus(), lwPubKey.getExponent()));

    X500NameBuilder x500NameBld = new X500NameBuilder(BCStyle.INSTANCE);

    x500NameBld.addRDN(BCStyle.C, "AU");
    x500NameBld.addRDN(BCStyle.O, "The Legion of the Bouncy Castle");
    x500NameBld.addRDN(BCStyle.L, "Melbourne");
    x500NameBld.addRDN(BCStyle.ST, "Victoria");
    x500NameBld.addRDN(BCStyle.EmailAddress, "[email protected]");

    X500Name    subject = x500NameBld.build();

    PKCS10CertificationRequestBuilder requestBuilder = new PKCS10CertificationRequestBuilder(subject, pubInfo);
                        
    PKCS10CertificationRequest req1 = requestBuilder.build(sigGen);

    PKCS10CertificationRequest req2 = new PKCS10CertificationRequest(req1.getEncoded());

    if (!req2.isSignatureValid(new BcRSAContentVerifierProviderBuilder(new DefaultDigestAlgorithmIdentifierFinder()).build(lwPubKey)))
    {
        fail("Failed verify check.");
    }

    if (!Arrays.areEqual(req2.getSubjectPublicKeyInfo().getEncoded(), req1.getSubjectPublicKeyInfo().getEncoded()))
    {
        fail("Failed public key check.");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:72,代码来源:PKCS10Test.java

示例6: generationTest

import org.bouncycastle.pkcs.PKCS10CertificationRequest; //导入方法依赖的package包/类
private void generationTest(int keySize, String keyName, String sigName)
    throws Exception
{
    AsymmetricCipherKeyPairGenerator kpg = new RSAKeyPairGenerator();
    RSAKeyGenerationParameters genParam = new RSAKeyGenerationParameters(
                                        BigInteger.valueOf(0x1001), new SecureRandom(), keySize, 25);

    kpg.init(genParam);

    AsymmetricCipherKeyPair kp = kpg.generateKeyPair();


    X500NameBuilder x500NameBld = new X500NameBuilder(RFC4519Style.INSTANCE);

    x500NameBld.addRDN(RFC4519Style.c, "AU");
    x500NameBld.addRDN(RFC4519Style.o, "The Legion of the Bouncy Castle");
    x500NameBld.addRDN(RFC4519Style.l, "Melbourne");
    x500NameBld.addRDN(RFC4519Style.st, "Victoria");
    x500NameBld.addRDN(PKCSObjectIdentifiers.pkcs_9_at_emailAddress, "[email protected]");

    X500Name subject = x500NameBld.build();

    PKCS10CertificationRequestBuilder requestBuilder = new BcPKCS10CertificationRequestBuilder(subject, kp.getPublic());

    DefaultSignatureAlgorithmIdentifierFinder sigAlgFinder = new DefaultSignatureAlgorithmIdentifierFinder();
    DefaultDigestAlgorithmIdentifierFinder digAlgFinder = new DefaultDigestAlgorithmIdentifierFinder();

    AlgorithmIdentifier sigAlgId = sigAlgFinder.find("SHA1withRSA");

    AlgorithmIdentifier digAlgId = digAlgFinder.find(sigAlgId);

    BcContentSignerBuilder contentSignerBuilder = new BcRSAContentSignerBuilder(sigAlgId, digAlgId);

    PKCS10CertificationRequest req1 = requestBuilder.build(contentSignerBuilder.build(kp.getPrivate()));

    BcPKCS10CertificationRequest req2 = new BcPKCS10CertificationRequest(req1.getEncoded());

    if (!req2.isSignatureValid(new BcRSAContentVerifierProviderBuilder(digAlgFinder).build(kp.getPublic())))
    {
        fail(sigName + ": Failed verify check.");
    }

    if (!Arrays.areEqual(req2.getSubjectPublicKeyInfo().getEncoded(), req1.getSubjectPublicKeyInfo().getEncoded()))
    {
        fail(keyName + ": Failed public key check.");
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:48,代码来源:BcPKCS10Test.java

示例7: createPSSTest

import org.bouncycastle.pkcs.PKCS10CertificationRequest; //导入方法依赖的package包/类
private void createPSSTest(String algorithm)
    throws Exception
{
    AsymmetricKeyParameter pubKey = new RSAKeyParameters(
        false,
        new BigInteger("a56e4a0e701017589a5187dc7ea841d156f2ec0e36ad52a44dfeb1e61f7ad991d8c51056ffedb162b4c0f283a12a88a394dff526ab7291cbb307ceabfce0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921cb23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef22e1e1f20d0ce8cffb2249bd9a2137",16),
        new BigInteger("010001",16));

    AsymmetricKeyParameter privKey = new RSAPrivateCrtKeyParameters(
        new BigInteger("a56e4a0e701017589a5187dc7ea841d156f2ec0e36ad52a44dfeb1e61f7ad991d8c51056ffedb162b4c0f283a12a88a394dff526ab7291cbb307ceabfce0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921cb23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef22e1e1f20d0ce8cffb2249bd9a2137",16),
        new BigInteger("010001",16),
        new BigInteger("33a5042a90b27d4f5451ca9bbbd0b44771a101af884340aef9885f2a4bbe92e894a724ac3c568c8f97853ad07c0266c8c6a3ca0929f1e8f11231884429fc4d9ae55fee896a10ce707c3ed7e734e44727a39574501a532683109c2abacaba283c31b4bd2f53c3ee37e352cee34f9e503bd80c0622ad79c6dcee883547c6a3b325",16),
        new BigInteger("e7e8942720a877517273a356053ea2a1bc0c94aa72d55c6e86296b2dfc967948c0a72cbccca7eacb35706e09a1df55a1535bd9b3cc34160b3b6dcd3eda8e6443",16),
        new BigInteger("b69dca1cf7d4d7ec81e75b90fcca874abcde123fd2700180aa90479b6e48de8d67ed24f9f19d85ba275874f542cd20dc723e6963364a1f9425452b269a6799fd",16),
        new BigInteger("28fa13938655be1f8a159cbaca5a72ea190c30089e19cd274a556f36c4f6e19f554b34c077790427bbdd8dd3ede2448328f385d81b30e8e43b2fffa027861979",16),
        new BigInteger("1a8b38f398fa712049898d7fb79ee0a77668791299cdfa09efc0e507acb21ed74301ef5bfd48be455eaeb6e1678255827580a8e4e8e14151d1510a82a3f2e729",16),
        new BigInteger("27156aba4126d24a81f3a528cbfb27f56886f840a9f6e86e17a44b94fe9319584b8e22fdde1e5a2e3bd8aa5ba8d8584194eb2190acf832b847f13a3d24a79f4d",16));

    DefaultSignatureAlgorithmIdentifierFinder sigAlgFinder = new DefaultSignatureAlgorithmIdentifierFinder();
    DefaultDigestAlgorithmIdentifierFinder digAlgFinder = new DefaultDigestAlgorithmIdentifierFinder();

    AlgorithmIdentifier sigAlgId = sigAlgFinder.find(algorithm);
    AlgorithmIdentifier digAlgId = digAlgFinder.find(sigAlgId);
    BcContentSignerBuilder contentSignerBuilder = new BcRSAContentSignerBuilder(sigAlgId, digAlgId);

    PKCS10CertificationRequest req = new BcPKCS10CertificationRequestBuilder(new X500Name("CN=XXX"), pubKey).build(contentSignerBuilder.build(privKey));
    if (!req.isSignatureValid(new BcRSAContentVerifierProviderBuilder(digAlgFinder).build(pubKey)))
    {
        fail("Failed verify check PSS.");
    }

    BcPKCS10CertificationRequest bcReq = new BcPKCS10CertificationRequest(req.getEncoded());
    if (!bcReq.isSignatureValid(new BcRSAContentVerifierProviderBuilder(digAlgFinder).build(bcReq.getPublicKey())))
    {
        fail("Failed verify check PSS encoded.");
    }

    if (!bcReq.getSignatureAlgorithm().getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS))
    {
        fail("PSS oid incorrect.");
    }

    if (bcReq.getSignatureAlgorithm().getParameters() == null)
    {
        fail("PSS parameters incorrect.");
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:48,代码来源:BcPKCS10Test.java

示例8: getCsrEncodedDer

import org.bouncycastle.pkcs.PKCS10CertificationRequest; //导入方法依赖的package包/类
/**
 * DER encode a CSR and PEM the encoding.
 *
 * @return The encoding
 * @param csr
 *            The CSR
 * @throws CryptoException
 * 				If CSR cannot be encoded
 */
public static byte[] getCsrEncodedDer(PKCS10CertificationRequest csr) throws CryptoException {
	try {
		return csr.getEncoded();
	} catch (IOException e) {
		throw new CryptoException(res.getString("NoEncodePkcs10Csr.exception.message"), e);
	}
}
 
开发者ID:kaikramer,项目名称:keystore-explorer,代码行数:17,代码来源:Pkcs10Util.java


注:本文中的org.bouncycastle.pkcs.PKCS10CertificationRequest.getEncoded方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。