我正在尝试使用OSGi条件权限机制.更具体地说,我正在尝试使用org.osgi.service.condpermadmin.BundleSignerCondition来限制可以启动哪些包.文档我已声明为了使用此权限,我必须使用org.osgi.framework.trust.repositories框架配置属性指定JKS密钥库的路径.但是,相同的文档提到此属性中提到的JKS必须没有密码.所以问题是:如何在没有密码的情况下创建JKS?Keytool实用程序拒绝使用空密码创建JKS.
Bal*_*dos 18
一段时间后,您无法使用keytool创建一个空白密码的密钥库,但您仍然可以通过编程方式进行密钥存储.
阅读这样的证书:
private static Certificate readCert(String path) throws IOException, CertificateException {
try (FileInputStream fin = new FileInputStream(path)) {
return CertificateFactory.getInstance("X.509").generateCertificate(fin);
}
}
Run Code Online (Sandbox Code Playgroud)
比如下创建带有空密码的密钥库:
try {
// Reading the cert
Certificate cert = readCert("/tmp/cert.cert");
// Creating an empty JKS keystore
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(null, null);
// Adding the cert to the keystore
keystore.setCertificateEntry("somecert", cert);
// Saving the keystore with a zero length password
FileOutputStream fout = new FileOutputStream("/tmp/keystore");
keystore.store(fout, new char[0]);
} catch (GeneralSecurityException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
运行命令:
keytool -list -keystore keystore
Run Code Online (Sandbox Code Playgroud)
它会要求输入密码,但您只需按一下输入即可.您将收到以下警告,但将列出密钥库的内容:
***************** WARNING WARNING WARNING *****************
* The integrity of the information stored in your keystore *
* has NOT been verified! In order to verify its integrity, *
* you must provide your keystore password. *
***************** WARNING WARNING WARNING *****************
Run Code Online (Sandbox Code Playgroud)
这可能对你有用.
| 归档时间: |
|
| 查看次数: |
16367 次 |
| 最近记录: |