我正在尝试使用Bouncy Castle生成证书,但我发现无法获取签发证书的 AuthorityKeyIdentifier。虽然我一直在尝试找出问题所在,但目前为止我还没有头绪。
我在存储中检查的证书具有 Authority Key Identifier。
使用这个方法,我得到了一个授权密钥标识符:
我在存储中检查的证书具有 Authority Key Identifier。
KeyID=64 c1 59 db eb e7 2b f0 d7 e5 e3 81 77 d2 be b0
Certificate Issuer:
CN=Test Certification Authority
Certificate SerialNumber=5c 27 00 3b 0f 0a a2 83 4a 8d 2b d5 45 d2 9c 3f
然而,每当我在Bouncy Castle中使用以下代码来获取密钥时,它会给我一个完全不同的AKI:
var password = "p@ssw0rd1";
var file = File.ReadAllBytes(@"C:\somefilepath\TESTCA.pfx");
Pkcs12Store st = new Pkcs12Store(new MemoryStream(file), password.ToCharArray());
var alias = st.Aliases.Cast<string>().Where (s => st.IsKeyEntry(s)).Single();
var cert = (X509Certificate)st.GetCertificate(alias).Certificate;
var subjectPKI = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo( cert.GetPublicKey());
var aki = new AuthorityKeyIdentifier(subjectPKI);
BitConverter.ToString(aki.GetKeyIdentifier()).Replace("-"," ").Dump();
使用这个方法,我得到了一个授权密钥标识符:
68 22 23 ED 45 82 A6 0E D6 A4 87 74 F2 E0 22 C4 4B F7 7D DF
然而,我在证书中找不到任何与此相匹配的信息。有什么想法吗?