使用Java KeyStore类。
InputStream keystoreStream = new FileInputStream(strKeystorePath);
KeyStore keystore = KeyStore.getInstance("JCEKS");
keystore.load(keystoreStream, strTrustStorePwd.toCharArray());
Key key = keystore.getKey(strAliasName, strTrustStorePwd.toCharArray());
load(InputStream stream, char[] password)
method with the correct password, it works fine. This error occurs when the keystore file has been modified or the password provided is incorrect.
InputStream keystoreStream = new FileInputStream(strKeystorePath);
KeyStore keystore = KeyStore.getInstance("JCEKS");
keystore.load(keystoreStream, null);
Key key = keystore.getKey(strAliasName, strTrustStorePwd.toCharArray());
软件运行正常,请确认load
和getKey
方法使用相同的密码。
当使用密码调用load()
和getKey
方法时,load()
方法会抛出错误,但是当使用null
密码调用load()
方法,以及使用相同的密码调用getKey
方法时,则可以正常运行。