我有一个经过自我验证的root ca证书,并且可能由root ca颁发了签名证书,两者均使用签名算法:SHA256WITHECDSA
当我使用openssl verify -verbose -CAfile ./localhost-7054.pem ./cert.pem
时说./cert.pem: OK
当我使用Java代码进行验证时,结果令人失望,这是我的代码,有人可以帮我吗?
public void test() throws Exception {
String orgPath = "C:\\Disk\\other\\test\\peerOrganizations\\org1.cnabs.com\\users\\Admin@org1.cnabs.com\\msp\\";
String caPath = "C:\\Disk\\other\\test\\peerOrganizations\\org1.cnabs.com\\users\\Admin@org1.cnabs.com\\msp\\";
JcaX509CertificateConverter converter = new JcaX509CertificateConverter().setProvider("BC");
X509CertificateHolder orgHolder = getCertificate(orgPath, "signcerts");
X509Certificate orgX509 = converter.getCertificate(orgHolder);
X509CertificateHolder caHolder = getCertificate(caPath, "cacerts");
X509Certificate caX509 = converter.getCertificate(caHolder);
// exception: certificate does not verify with supplied key
orgX509.verify(caX509.getPublicKey());
}
以下是ca的pem格式:
-----BEGIN CERTIFICATE-----
MIICFzCCAb2gAwIBAgIUDxMZ0vUzR0+rXeF7g5JxE8rVbbIwCgYIKoZIzj0EAwIw
aDELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQK
EwtIeXBlcmxlZGdlcjEPMA0GA1UECxMGRmFicmljMRkwFwYDVQQDExBmYWJyaWMt
Y2Etc2VydmVyMB4XDTE5MDUyODEyNTYwMFoXDTM0MDUyNDEyNTYwMFowaDELMAkG
A1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQKEwtIeXBl
cmxlZGdlcjEPMA0GA1UECxMGRmFicmljMRkwFwYDVQQDExBmYWJyaWMtY2Etc2Vy
dmVyMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEJjvObbd9JPeyyxkckVutSN+F
e1Lzukj86byHXwLN4ycsPGQHxChX7+d29mPRlLk6phpd2a04qlLkzmHaggYdQKNF
MEMwDgYDVR0PAQH/BA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