本文整理汇总了Java中org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequestBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Java JcaPKCS10CertificationRequestBuilder.build方法的具体用法?Java JcaPKCS10CertificationRequestBuilder.build怎么用?Java JcaPKCS10CertificationRequestBuilder.build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequestBuilder
的用法示例。
在下文中一共展示了JcaPKCS10CertificationRequestBuilder.build方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSigningRequest
import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequestBuilder; //导入方法依赖的package包/类
/**
* Creates and returns the content of a new singing request for the specified certificate. Signing
* requests are required by Certificate Authorities as part of their signing process. The signing request
* contains information about the certificate issuer, subject DN, subject alternative names and public key.
* Private keys are not included. After the Certificate Authority verified and signed the certificate a new
* certificate is going to be returned.
*
* @param cert the certificate to create a signing request.
* @param privKey the private key of the certificate.
* @return the content of a new singing request for the specified certificate.
*/
public static String createSigningRequest(X509Certificate cert, PrivateKey privKey) throws OperatorCreationException, IOException {
JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder( //
cert.getSubjectX500Principal(), //
cert.getPublicKey() //
);
String signatureAlgorithm = "SHA256WITH" + cert.getPublicKey().getAlgorithm();
ContentSigner signer = new JcaContentSignerBuilder(signatureAlgorithm).build(privKey);
PKCS10CertificationRequest csr = csrBuilder.build(signer);
StringWriter string = new StringWriter();
PemWriter pemWriter = new PemWriter(string);
PemObjectGenerator objGen = new MiscPEMGenerator(csr);
pemWriter.writeObject(objGen);
pemWriter.close();
return string.toString();
}
示例2: generatePKCS10CSR
import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequestBuilder; //导入方法依赖的package包/类
/**
* Create a PKCS #10 certification request (CSR) using the supplied certificate and private key.
*
* @param cert The certificate
* @param privateKey The private key
* @throws CryptoException If there was a problem generating the CSR
* @return The CSR
*/
public static PKCS10CertificationRequest generatePKCS10CSR(X509Certificate cert, PrivateKey privateKey)
throws CryptoException
{
X500Name subject = new X500Name(cert.getSubjectDN().toString());
JcaPKCS10CertificationRequestBuilder csrBuilder =
new JcaPKCS10CertificationRequestBuilder(subject, cert.getPublicKey());
JcaContentSignerBuilder signerBuilder = new JcaContentSignerBuilder(cert.getSigAlgName());
try
{
ContentVerifierProvider prov = new JcaContentVerifierProviderBuilder().build(cert);
PKCS10CertificationRequest csr = csrBuilder.build(signerBuilder.build(privateKey));
if (!csr.isSignatureValid(prov))
{
throw new CryptoException(RB.getString("NoVerifyGenCsr.exception.message"));
}
return csr;
}
catch (OperatorCreationException | PKCSException ex)
{
throw new CryptoException(RB.getString("NoGenerateCsr.exception.message"), ex);
}
}