我正在尝试以以下方式验证使用 Java 提供给我的证书
try{
FileInputStream fr = new FileInputStream(pathtoCertificate);
CertificateFactory cf = CertificateFactory.getInstance("X509");
X509Certificate c = (X509Certificate)
cf.generateCertificate(fr);
System.out.println("++++Certificate Verification++++++++");
PublicKey pk = c.getPublicKey();
c.verify(pk);....//63
System.out.println("++This certificate is VALID++");
.....
}
catch(CertificateException e){
e.printStackTrace();
System.out.println("Certificate is Invalid");
}
但是,我不断收到以下错误
java.security.SignatureException: Signature does not match.
at sun.security.x509.X509CertImpl.verify(Unknown Source)
at sun.security.x509.X509CertImpl.verify(Unknown Source)
at Main.printCertificate(Main.java:63)
at Main.main(Main.java:41)
我只获得了一个证书文件(我需要验证)、一个私钥(对应于上述文件)和来自 CA 的证书。我对 Java 安全性很陌生。因此,任何关于如何验证证书文件的想法都会很棒。