証明書を2つ持っています。1 つの証明書が別の証明書の発行者です。
私の発行者証明書が実際に発行者であることをJavaコードで確認するにはどうすればよいですか?
私は、自分の証明書の AuthorityKeyIdentifier と発行者証明書の SubjectKeyIdentify が同じでなければならないことを知っています。確認しましたが、同じです。
しかし、Javaコードを使用すると、次の結果が得られます。
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
InputStream usrCertificateIn = new FileInputStream("/usr.cer");
X509Certificate cert = (X509Certificate) certFactory.generateCertificate(usrCertificateIn);
InputStream SiningCACertificateIn = new FileInputStream("/siningCA.cer");
X509Certificate issuer = (X509Certificate) certFactory.generateCertificate(SiningCACertificateIn);
byte[] octets = (ASN1OctetString.getInstance(cert.getExtensionValue("2.5.29.35")).getOctets());
System.out.println(Arrays.toString(octets) + " bouncycastle, AuthorityKeyIdentifier");
System.out.println(Arrays.toString(cert.getExtensionValue("2.5.29.35")) + "java.security, AuthorityKeyIdentifier");
octets = ASN1OctetString.getInstance(issuer.getExtensionValue("2.5.29.14")).getOctets();
System.out.println((Arrays.toString(octets) + "bouncycastle, SubjectKeyIdentifie "));
System.out.println(Arrays.toString(issuer.getExtensionValue("2.5.29.14")) + "java.security, SubjectKeyIdentifie ");
その結果は次のとおりです。
[48, 22, -128, 20, 52, -105, 49, -70, -24, 78, 127, -113, -25, 55, 39, 99, 46, 6, 31, 66, -55, -86、 -79、113 ] bouncycastle、AuthorityKeyIdentifier
[ 4 , 24, 48, 22, -128, 20, 52, -105, 49, -70, -24, 78, 127, -113, -25, 55, 39, 99, 46, 6, 31, 66 , -55, -86, -79, 113 ]java.security, AuthorityKeyIdentifier
そして、同じでなければならない別のバイト配列が、配列の先頭に別のバイトが追加されます。
[ 4, 20, 52, -105, 49, -70, -24, 78, 127, -113, -25, 55, 39, 99, 46, 6, 31, 66, -55, -86, -79 、113 ] bouncycastle、SubjectKeyIdentify
[4, 22, 4, 20, 52, -105, 49, -70, -24, 78, 127, -113, -25, 55, 39, 99, 46, 6, 31, 66, -55, - 86、-79、113 ]java.security、SubjectKeyIdentify
質問 1) キー識別子を計算して同じ配列を取得できますか?
質問 2) ある証明書が別の証明書の発行者であることを証明する別の方法はありますか。