title: Decryption failed when storing the key inside Java key store
body: <p>I've created an encryption key by the following code:</p>
  
  <pre><code>SecretKeyFactory skFactory = SecretKeyFactory.getInstance("PBEWithSHA1AndDESede");
  SecretKey key = skFactory.generateSecret(new PBEKeySpec("&lt;some password&gt;".toCharArray()));
  </code></pre>
  
  <p>Then I've used the key to encrypt some text.</p>
  
  <p>I've stored this key inside a java key store and saved in on FS:</p>
  
  <pre><code>KeyStore ks = KeyStore.getInstance("JCEKS");
  ks.setKeyEntry(keyAlias, key ,keyPassword.toCharArray(), null);
  FileOutputStream fileOutputStream = new FileOutputStream (keyStorePath);
  keyStore.store(fileOutputStream , keyStorePassword.toCharArray());
  fileOutputStream.close();
  </code></pre>
  
  <p>In a different process I open the key store and try to decrypt some text:</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>When trying to decrypt the text I get the error: </p>
  
  <pre><code>java.security.InvalidKeyException: Given final block not properly padded
  </code></pre>
  
  <p>If I try to use the key without storing it in the key store immediately after creating it, the decription proccess is working great.</p>
  
  <p>Any ideas?</p>