证书注册过程

我正在寻找一个注册证书的程序。

我search了很多,但没有find一个很好的答案。现在我得到,首先我必须生成一个密钥存储区(创build一个公钥和一个私钥)然后私钥应保持私人和公钥是发送与其他信息(如姓名,组织)到CA.然后CA会生成一些东西,并给我回来,其中包含公钥和信息。

直到现在我得到这个,但什么CA生成? 什么是P12文件和什么是.cer文件包含?

任何人都可以帮助我解决这个问题,我真的很无奈。 提前致谢。

在公共密钥基础设施中颁发证书的一般程序是如下。

1)客户端生成密钥对,私钥和公钥

2)客户端生成包括通用名称和公共密钥之类的属性的CSR(证书签名请求)。 用私钥签名并发送给服务器

3)服务器用CSR数据build立X509证书,用CA私钥生成X509证书,并将X509返回给客户端

4)客户端将私钥和证书存储在KeyStore中

什么CA生成?

x509证书

什么是P12文件

包含密钥库的PKCS#12格式(.pfx,.p12)文件

什么是.cer文件包含

DER或PEM格式的证书(非私钥)的公共部分

EDITED – Android上的CSR一代

Gradle依赖关系

compile 'com.madgag.spongycastle:core:1.51.0.0' compile 'com.madgag.spongycastle:pkix:1.51.0.0' 

生成KeyPair和CSR

 //Generate KeyPair KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(KEY_SIZE, new SecureRandom()); KeyPair keyPair = keyGen.generateKeyPair(); //Generate CSR in PKCS#10 format encoded in DER PKCS10CertificationRequest csr = CsrHelper.generateCSR(keyPair, commonname); byte CSRder[] = csr.getEncoded(); 

公用事业

 public class CsrHelper { private final static String DEFAULT_SIGNATURE_ALGORITHM = "SHA256withRSA"; private final static String CN_PATTERN = "CN=%s, O=Aralink, OU=OrgUnit"; private static class JCESigner implements ContentSigner { private static Map<String, AlgorithmIdentifier> ALGOS = new HashMap<String, AlgorithmIdentifier>(); static { ALGOS.put("SHA256withRSA".toLowerCase(), new AlgorithmIdentifier( new ASN1ObjectIdentifier("1.2.840.113549.1.1.11"))); ALGOS.put("SHA1withRSA".toLowerCase(), new AlgorithmIdentifier( new ASN1ObjectIdentifier("1.2.840.113549.1.1.5"))); } private String mAlgo; private Signature signature; private ByteArrayOutputStream outputStream; public JCESigner(PrivateKey privateKey, String sigAlgo) { //Utils.throwIfNull(privateKey, sigAlgo); mAlgo = sigAlgo.toLowerCase(); try { this.outputStream = new ByteArrayOutputStream(); this.signature = Signature.getInstance(sigAlgo); this.signature.initSign(privateKey); } catch (GeneralSecurityException gse) { throw new IllegalArgumentException(gse.getMessage()); } } @Override public AlgorithmIdentifier getAlgorithmIdentifier() { AlgorithmIdentifier id = ALGOS.get(mAlgo); if (id == null) { throw new IllegalArgumentException("Does not support algo: " + mAlgo); } return id; } @Override public OutputStream getOutputStream() { return outputStream; } @Override public byte[] getSignature() { try { signature.update(outputStream.toByteArray()); return signature.sign(); } catch (GeneralSecurityException gse) { gse.printStackTrace(); return null; } } } //Create the certificate signing request (CSR) from private and public keys public static PKCS10CertificationRequest generateCSR(KeyPair keyPair, String cn) throws IOException, OperatorCreationException { String principal = String.format(CN_PATTERN, cn); ContentSigner signer = new JCESigner (keyPair.getPrivate(),DEFAULT_SIGNATURE_ALGORITHM); PKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder( new X500Name(principal), keyPair.getPublic()); ExtensionsGenerator extensionsGenerator = new ExtensionsGenerator(); extensionsGenerator.addExtension(Extension.basicConstraints, true, new BasicConstraints( true)); csrBuilder.addAttribute(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest, extensionsGenerator.generate()); PKCS10CertificationRequest csr = csrBuilder.build(signer); return csr; } }