【发布时间】:2019-03-12 06:30:49
【问题描述】:
我正在尝试将我自己的密钥存储在 PKCS12 密钥库中。我尝试使用以下代码:
char[] passArray = "password".toCharArray();// this is key store pass
String key = "test123"; // this is my own secret key
// Loading a Keystore
KeyStore p12KeyStore = KeyStore.getInstance("PKCS12");
p12KeyStore.load(new FileInputStream("testKeyStore.p12"), passArray);
存储我自己的密钥,如下所示:
byte [] byteKey = key.getBytes();
SecretKeySpec keySpec = new SecretKeySpec(byteKey, "DSA");
KeyStore.SecretKeyEntry secret = new KeyStore.SecretKeyEntry(keySpec);
KeyStore.ProtectionParameter password = new KeyStore.PasswordProtection(passArray);
p12KeyStore.setEntry("secret-key", secret, password);
但我不确定是否按照最佳实践存储我自己的密钥。以及尝试从密钥库获取我自己的密钥时,因为它不像我原来的密钥。
Key eKey = p12KeyStore.getKey("secret-key", passArray);
谁能帮我在 PKCS12 密钥库中存储和获取我自己的秘密?
【问题讨论】: