gpt4 book ai didi

java - 从 keystore 加载证书

转载 作者:行者123 更新时间:2023-11-30 04:31:07 24 4
gpt4 key购买 nike

我有一个 Base-64 编码的 X.509 (.CER) 证书,它导致下面的 java 代码出现 NullPointerException。导致它的行是 PublicKey pubKey = pubCert.getPublicKey();

有没有办法验证 myfile.keystore 是否具有“xyz”证书?

final FileInputStream keyFile = new FileInputStream(filePath
+ "myfile.keystore");
final KeyStore keyStore = KeyStore.getInstance("JKS");
String storepass = "mypass";
keyStore.load(keyFile, storepass.toCharArray());
Certificate pubCert = keyStore.getCertificate("xyz");
PublicKey pubKey = pubCert.getPublicKey();

最佳答案

尝试 JRE 或 JDK bin 目录中的 keytool 命令,请参阅下面的输出:

@raspbmc:~$ /opt/jdk1.8.0/bin/keytool  -list -help
keytool -list [OPTION]...

Lists entries in a keystore

Options:

-rfc output in RFC style
-alias <alias> alias name of the entry to process
-keystore <keystore> keystore name
-storepass <arg> keystore password
-storetype <storetype> keystore type
-providername <providername> provider name
-providerclass <providerclass> provider class name
-providerarg <arg> provider argument
-providerpath <pathlist> provider classpath
-v verbose output
-protected password through protected mechanism

Use "keytool -help" for all available commands

引用:

http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/keytool.html

关于java - 从 keystore 加载证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14637677/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com