java pfx_如何在Java中读取.pfx文件的内容?

java pfx_如何在Java中读取.pfx文件的内容?我有file.pfx文件,还有一个私钥.如何在Java中读取file.pfx中的证书?我用过这段代码:importjava.security.*;importjava.security.cert.Certificate;importjava.security.cert.X509Certificate;importjava.security.cert.CertificateException…

大家好,又见面了,我是你们的朋友全栈君。

我有file.pfx文件,还有一个私钥.如何在

Java中读取file.pfx中的证书?

我用过这段代码:

import java.security.*;

import java.security.cert.Certificate;

import java.security.cert.X509Certificate;

import java.security.cert.CertificateException;

import javax.crypto.SecretKey;

import javax.security.auth.callback.*;

//These packages I have used.

public String readFile(String fn) {

String thisLine, ret = “”;

KeyStore ks = KeyStore.getInstance(“pkcs12”, “SunJSSE”);

ks.load(new FileInputStream(fn),”password”.toCharArray());

try {

Key key = ks.getKey(“1”, “password”.toCharArray());

Certificate[] cc = ks.getCertificateChain(“1”);

X509Certificate certificate1 = (X509Certificate) cc[0];//Here it throws java.lang.NullPointerException

ret += certificate1.getNotAfter();

ret += certificate1.getNotBefore();

} catch(Exception e) {

ret = “Cannot load, exception!”;

}

return ret;

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/134292.html原文链接:https://javaforall.net

(0)
上一篇 2022年6月7日 上午6:46
下一篇 2022年6月7日 上午6:46


相关推荐

  • Openclaw新手踩坑

    Openclaw新手踩坑

    2026年3月13日
    1
  • navicat15激活码linux_在线激活

    (navicat15激活码linux)这是一篇idea技术相关文章,由全栈君为大家提供,主要知识点是关于2021JetBrains全家桶永久激活码的内容IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.htmlS32PGH0SQB-eyJsaWN…

    2022年3月26日
    67
  • 二分法排序C++

    二分法排序C++include includevoidT intarray intn nbsp nbsp nbsp nbsp nbsp nbsp intleft right num nbsp nbsp nbsp nbsp nbsp nbsp intmiddle j i nbsp nbsp nbsp nbsp nbsp nbsp for i 1 i nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp left 0 准备 nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp right i 1

    2026年3月18日
    2
  • 二级Python选择题_二级python选择题题库

    二级Python选择题_二级python选择题题库上半部分–>请点击https://blog.csdn.net/ExclusiveName/article/details/104537575第七套真题在面向对象方法中,一个对象请求另一对象为其服务的方式是通过发送___________。A命令B口令C消息D调用语句正确答案:C下面不属于软件需求分析阶段主要工作的是___________。A需…

    2022年8月31日
    7
  • Java8 Lambda表达式教程

    Java8新特性,Lambda表达式与集合类bulkoperation教程。迄今为止最全面的中文原创javalambda表达式教程。

    2022年4月7日
    52
  • pycharm的运行环境_pycharm新环境怎么选

    pycharm的运行环境_pycharm新环境怎么选一直用pycharm写代码一直用anaconda管理python环境但是今天我居然发现我不会更改pycharm当前的运行环境到我新建的anacondaenvironment中!配置:系统:win10;GPU:NVIDIAGeForceGTX1050Ti管理平台:anaconda3IDE:Pycharm问题我的anaconda里面有三个环境,第一个是自…

    2022年8月26日
    7

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号