数字签名:用于验证和提取认证信息的示例代码

发布于 2024-11-10 04:35:34 字数 245 浏览 8 评论 0原文

我使用第三方工具来验证签名并从签名中获取证书详细信息(如序列号、CA 等)。该实用程序的问题是它已获得许可并且只能在某些机器上运行。

我可以使用简单的 java 或 .net 代码验证数据签名吗?(而不是使用付费应用程序)。我没有私钥来从签名数据中提取证书信息。

或者,如果我有 pfx 文件,有人可以建议 java 或 .net 中的示例代码来提取证书详细信息。来自签名数据。

数据使用非对称加密进行签名。

I use a third party tool to verify signature and to get certificate detail(like serial number, CA etc..) from signature. The problem with this utility is it is licensed and works on certain machines only.

Can i validate the signature against the data using simple java or .net code?(instead of using paid application). I dont have private key to extract certificate information from signed data.

Or if someone can suggest sample code in java or .net to extract certificate detail if i have pfx file. Of from signed data.

Data is signed with asymmetric encryption.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沉默的熊 2024-11-17 04:35:34

要从证书中提取详细信息:

  1. 创建一个保存证书数据的字符串。只需确保其开头有 -----BEGIN CERTIFICATE----- ,结尾有 -----END CERTIFICATE----- 即可。
  2. 现在,在 Java 中使用以下代码来提取证书详细信息。

<代码>

InputStream inStream = new ByteArrayInputStream(certString.toString().getBytes("UTF-8"));
BufferedInputStream bis = new BufferedInputStream(inStream);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Certificate cert = cf.generateCertificate(bis);
X509Certificate xCert = (X509Certificate)cert;

System.out.println("Certificate Type: "+cert.getType());
System.out.println("Public Key: \n"+cert.getPublicKey());
try{
      System.out.println("Signature Algorithm"+xCert.getSigAlgName());
      System.out.println("IssuerDN : "+xCert.getIssuerDN());
      System.out.println("Serial Number : "+xCert.getSerialNumber());
      System.out.println("SubjectDN : "+xCert.getSubjectDN());
}catch(Exception exp){
      :
}

<代码>

To extract detail from certificate:

  1. Make a string which keeps certificate data. Just ensure it has -----BEGIN CERTIFICATE----- in starting and -----END CERTIFICATE----- in end.
  2. Now use the following code in Java to extract certificate detail.

InputStream inStream = new ByteArrayInputStream(certString.toString().getBytes("UTF-8"));
BufferedInputStream bis = new BufferedInputStream(inStream);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Certificate cert = cf.generateCertificate(bis);
X509Certificate xCert = (X509Certificate)cert;

System.out.println("Certificate Type: "+cert.getType());
System.out.println("Public Key: \n"+cert.getPublicKey());
try{
      System.out.println("Signature Algorithm"+xCert.getSigAlgName());
      System.out.println("IssuerDN : "+xCert.getIssuerDN());
      System.out.println("Serial Number : "+xCert.getSerialNumber());
      System.out.println("SubjectDN : "+xCert.getSubjectDN());
}catch(Exception exp){
      :
}

蝶舞 2024-11-17 04:35:34

如果您有 PFX 文件,那么它可能包含验证签名所需的公钥证书。

或者,如果您的签名是 PKCS#7 签名,则签名本身将保存数据、签名和证书。假设 PKCS#7 未分离。

您需要询问您的签名者,他如何传输他的证书进行验证。

If you are having the PFX file, then that may contain the public key certificate which will be required to verify the signature.

Alternatively, if your signature is a PKCS#7 signature, then the signature itself will hold the data, signature and the certificate. Assuming PKCS#7 is not detached.

You need to ask your signer, how is he transferring his certificate for validation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文