Leaf Certificate 和 Sub Certificate 有什么用,如何使用?
What's the Leaf Certificate and Sub Certificate used for and how to use them?
我在使用 AppleWallet 做生意时遇到了问题。
他们给了我三个证书:
- 字符串格式的叶子证书;
- 字符串格式的子证书;
- Apple Root CA - G3 证书文件,以“.cer”结尾
我的问题:如何使用 RSA 算法验证和编码数据?
PS:文档明确表示PublicKey是由Leaf Certificate提供的。并且三证上链。 Leaf Certificate由Sub Certificate签名,Sub Certificate由AppleRootCA签名-G3.cer.
我需要做两件事:
- 验证三个证书。
- 从叶证书中提取 RSA 公钥。
我不知道该怎么做。
您基本上要做的就是构建一个证书链(如果您没有将其作为链获得)。证书链基本上由位于第 0 个位置的最终实体证书(也称为叶证书,链中最重要的证书)和次要证书组成。 CA 证书最不重要。
这就是通常的 X.509 证书链的样子:
3. CA Certificate (self-signed)
|
|__ 2. Sub CA Certificate (signed by the above CA)
|
|__ 1. Sub-sub CA Certificate (if any) (signed by the above Sub CA)
|
|__ 0. End Entity Certificate (your certificate, signed by the above cert)
当您从每个证书自己构建证书链时,您必须查看哪个证书是由谁签署的,然后以上述方式构建链(树中的数字表示索引中的索引) java 的证书数组)。
您可以通过查看 SubjectDN 和 IssuerDN 找到由谁签署的证书。 Subject 可分辨名称是最终实体,Issuer 可分辨名称是签署您的证书的实体的名称。
如果您需要以编程方式验证证书是否由另一个证书签名,您可以这样做:
userCert.verify(caCert.getPublicKey());
您可以使用以下代码片段从证书中提取 public 密钥:
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
// Provided the certificate doesn't have certificate headers (---begin cert--- and ---end cert---)
Certificate cert = certificateFactory.generateCertificate(new FileInputStream(new File("CERTIFICATE_PATH")));
System.out.println(cert.getPublicKey());
我在使用 AppleWallet 做生意时遇到了问题。 他们给了我三个证书:
- 字符串格式的叶子证书;
- 字符串格式的子证书;
- Apple Root CA - G3 证书文件,以“.cer”结尾
我的问题:如何使用 RSA 算法验证和编码数据?
PS:文档明确表示PublicKey是由Leaf Certificate提供的。并且三证上链。 Leaf Certificate由Sub Certificate签名,Sub Certificate由AppleRootCA签名-G3.cer.
我需要做两件事:
- 验证三个证书。
- 从叶证书中提取 RSA 公钥。
我不知道该怎么做。
您基本上要做的就是构建一个证书链(如果您没有将其作为链获得)。证书链基本上由位于第 0 个位置的最终实体证书(也称为叶证书,链中最重要的证书)和次要证书组成。 CA 证书最不重要。
这就是通常的 X.509 证书链的样子:
3. CA Certificate (self-signed)
|
|__ 2. Sub CA Certificate (signed by the above CA)
|
|__ 1. Sub-sub CA Certificate (if any) (signed by the above Sub CA)
|
|__ 0. End Entity Certificate (your certificate, signed by the above cert)
当您从每个证书自己构建证书链时,您必须查看哪个证书是由谁签署的,然后以上述方式构建链(树中的数字表示索引中的索引) java 的证书数组)。
您可以通过查看 SubjectDN 和 IssuerDN 找到由谁签署的证书。 Subject 可分辨名称是最终实体,Issuer 可分辨名称是签署您的证书的实体的名称。
如果您需要以编程方式验证证书是否由另一个证书签名,您可以这样做:
userCert.verify(caCert.getPublicKey());
您可以使用以下代码片段从证书中提取 public 密钥:
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
// Provided the certificate doesn't have certificate headers (---begin cert--- and ---end cert---)
Certificate cert = certificateFactory.generateCertificate(new FileInputStream(new File("CERTIFICATE_PATH")));
System.out.println(cert.getPublicKey());