我可以从 X509Certificate
实例中提取 OID 和签名算法的名称,例如 "SHA256WithRSA"
但如何提取摘要算法的名称,例如例如“SHA256”
。
除了 "with"
的字符串分割或 OID 的固定映射之外,还有其他方法吗?
附带问题:拆分“with”
是否安全?
最佳答案
证书仅包含签名算法 OID,它映射到唯一的一对摘要/算法。因此,找到摘要算法的最简单方法是使用映射表 OID -> 摘要算法。
不幸的是,我不知道可以在哪里找到这些 OID 的集中位置。但是,它们可以收集在这些 RFC 中:
- Algorithms and Identifiers for the Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile
- Additional Algorithms and Identifiers for RSA Cryptography for use in the Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile
- Updates for RSAES-OAEP and RSASSA-PSS Algorithm Parameters
- Internet X.509 Public Key Infrastructure: Additional Algorithms and Identifiers for DSA and ECDSA
解析算法名称并按“With”拆分应该可以工作,但有这些限制
- 它可能仅适用于 Oracle Cryptography 提供程序(请参阅 signature algorithm naming conventions 上的文档)。另一个具有自己的证书实现的提供商可能会使用另一个不兼容的命名约定。
- 如果算法未知,
getSigAlgName()
方法将返回OID.a.b.c.d...
形式的字符串。例如,旧版 Java6 不支持SHA256withDSA
算法,将打印OID.2.16.840.1.101.3.4.3.2
关于java - 如何从 X509Certificate 中提取摘要算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23294540/