如何检查X509Certificate是否是CA证书? [英] How to check if X509Certificate is CA certificate?
问题描述
我有一个X509Certificate实例在Java,我需要确定它是一个CA证书或用户证书。
I have a X509Certificate instance in Java and I need to identify if it is a CA certificate or user certificate.
任何人都可以提供任何帮助?
Can anyone provide any help?
推荐答案
根据我所做的研究,可以通过检查基本约束来检查!
检查 API 以返回结果 getBasicConstraints()
方法。
According to research I have performed, it can be checked by checking basic constraints!
Check the API for returning results of getBasicConstraints()
method.
所以如果方法返回result != -1
,证书可以视为 CA证书
。
So if the method returns result != -1
, a certificate can be considered as a CA certificate
.
与多个 CA证书
(根和中间),它的工作原理如上所述。
我也用几个用户证书检查过这个方法,并且方法返回-1作为结果。
I have checked this with several CA certificates
(root and intermediate), and it works as described.
I have also checked this method with several user certificates, and the method returns -1 as result.
这篇关于如何检查X509Certificate是否是CA证书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!