给定证书和 CA 的公钥,我只想解密签名部分以将其用于验证。 RSA 签名解密定义为:H'=s^e mod n
其中s
是签名。我使用 BigInteger 手动进行了解密,如下代码所示,但它看起来不太好,因为当我生成证书的 SHA1 哈希值(使用 getTBSCertificate() 方法)时,结果看起来不一样。是否有一个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);
最佳答案
您只需调用Certificate.verify()。
不存在解密数字签名之类的事情。
关于java - 如何解密X509证书签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21945036/