java如何解密X509证书签名
给定证书和CA的公钥,我只想解密签名部分以用于验证。RSA签名解密定义为:H'=s^e mod n
,其中s
是签名。我使用BigInteger作为以下代码手动进行了解密,但它似乎不正常,因为在生成证书的SHA1哈希值时(使用getTBCertificate()方法),结果看起来不一样。是否有一个java类接受(证书+CA的公钥)并生成解密的签名
File f= new File("/Users/AA/Desktop/InCommonServerCA"); // path for CA certificate
CertificateFactory cf = CertificateFactory.getInstance("X.509");
BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
Certificate certCA = cf.generateCertificate(in);
RSAPublicKey pub = (RSAPublicKey) certCA.getPublicKey();
BigInteger n= pub.getModulus(); // to get the CA's modulus (n)
BigInteger e=pub.getPublicExponent(); // to get the CA's exponent (e)
in.close();
// implement `H'=s^e mod n`
BigInteger h1, signature;
signature= new BigInteger(x509cert.getSignature());
h1=signature.modPow(e, n);
# 1 楼答案
您只需调用证书即可。验证()
没有解密数字签名这样的事情