本文介绍了如何以编程方式创建新的KeyStore?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式在Java中创建一个新的密钥库。以下代码:

I'm trying to programmatically create a new keystore in Java. The following code:

KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.setCertificateEntry("alias", cert);

抛出未初始化的KeyStore异常。

throws a Uninitialized KeyStore exception.

推荐答案

KeyStore需要在创建后加载。 load方法要求FileInputStream读取,但如果你提供null,则加载一个空的KeyStore。

The KeyStore needs to be loaded after it has been created. The load method asks for a FileInputStream to read from but if you supply a null one, an empty KeyStore is loaded.

参见

这篇关于如何以编程方式创建新的KeyStore?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 13:58