0
裏面的關鍵當我創建通過下面的代碼的加密密鑰失敗。解密存儲Java密鑰存儲
我已經存儲在Java密鑰存儲在這裏面的關鍵,並保存在FS:
KeyStore ks = KeyStore.getInstance("JCEKS");
ks.setKeyEntry(keyAlias, key ,keyPassword.toCharArray(), null);
FileOutputStream fileOutputStream = new FileOutputStream (keyStorePath);
keyStore.store(fileOutputStream , keyStorePassword.toCharArray());
fileOutputStream.close();
在不同的過程中,我打開密鑰存儲,並嘗試解密一些文字:
KeyStore ks2 = KeyStore.getInstance("JCEKS");
ks2.load(new java.io.FileInputStream(keyStorePath), ksPassword.toCharArray());
SecretKeyFactory skFactory2 = SecretKeyFactory.getInstance("PBEWithSHA1AndDESede");
String passForTheKey = ks2.getKey(keyAlias, keyPass.toCharArray()).toString();
KeySpec key = new PBEKeySpec(passForTheKey.toCharArray());
SecretKey sKey2 = skFactory.generateSecret(key);
當試圖解密文本我得到的錯誤:
java.security.InvalidKeyException: Given final block not properly padded
如果我嘗試使用鍵,但不將其存儲在T他在創建它之後立即關鍵存儲,其刻錄過程效果很好。
任何想法?
哦!我沒有看到......謝謝! – 2011-06-16 13:55:48