我创建了一个等于X509Certificate#certificate.getPublicKey().getAlgorithm()的java方法
用我的绳子。但是当我调用getPublicKey()时有bug --它是空的,我有ArrayIndexOutOfBoundsException。如何解决这个问题。条件(getPublicKey != null)对我不起作用。
public boolean supports(X509Certificate certificate) {
try {
final String algorithm = certificate.getPublicKey().getAlgorithm();
if ("RSA".equals(algorithm)) {
return certificate.getSignature().length * 8 == keySize;
}
} catch (ArrayIndexOutOfBoundsException ex) {
log.warn(" can't get the public key from certificate ", ex);
}
return false;
}
}也许需要一些条件?
我希望我的应用程序不要崩溃。
发布于 2022-01-26 06:56:24
我用这个条件修复了它
boolean[] withKeys = certificate.getKeyUsage();
if (withKeys != null && withKeys[5]) 您也可以检查您的公钥是否可用。
java.security.cert.X509Certificate#getKeyUsage()https://stackoverflow.com/questions/70851907
复制相似问题