我有客户端提供的CSR文件,我能够通过JcaPKCS10CertificationRequest getPublicKey()。getAlgorithm()方法找到密钥类型(RSA / DSA),但是我找不到任何合适的方法来确定长度/公钥的大小(例如:1024/2048/4096位)。
据我了解,没有任何通用的方法来获取公共密钥的“密钥大小”。相反,请检查您的公钥以查看它是否实现了RSAPublicKey或DSAPublicKey之类的接口。如果是这样,请使用各种接口方法从密钥中提取属性并获取该属性的位长,例如:
PublicKey publicKey = yourRequest.getPublicKey();
int keySize
if (publicKey instanceof RSAPublicKey) {
keySize = ((RSAPublicKey)publicKey).getPublicExponent().bitLength();
} else if (publicKey instance DSAPublicKey) {
keySize = ((DSAPublicKey)publicKey).getY().bitLength();
} else {
// handle other public key types.
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句