java - 如何解密X509证书签名

标签 java x509certificate digital-signature

给定证书和 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/

相关文章:

c# - 从公钥(不是证书)构建 RSACryptoServiceProvider

java - 验证时如何将PDF注释与签名连接起来?

pdf - 使用 IText 7 签署 Pdf 时的 Java 堆空间

java - 修复Java虚拟机热点错误的解决方案?

java - 将 .jar 许可证文件添加到 Docker 镜像的类路径?

c# - X509Store Certificates.Find FindByThumbprint 问题

java - 如何用 Java 生成 PGP 证书

java - 使用 iText 签名,Adobe Reader 报告 "Signature was created using Not available."

java - getTypeParameters 返回一个空的 TypeVariable 数组

java - JSon 根据应用于其他节点的条件选择节点?