title: KeyStore.setKeyEntry give java.security.KeyStoreException: Failed to store private key, then upgrading to Android 9 Pie
body: <p>My code</p>
  
  <pre><code>    try {
          KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); 
          KeyPair keyPair = keyGen.generateKeyPair(); 
          RSAKey privateKeyResult = (RSAKey) keyPair.getPrivate();
          if(keyStore!=null) {
              keyStore.setKeyEntry(alias, (Key) privateKeyResult, null, new Certificate[]{certificate});
          ...
      } catch (KeyStoreException e) {
          logger.error("Error in insertion to keystore", e);
      }
  </code></pre>
  
  <p>don't work when the user upgrade the Android operating system from Oreo to   Pie (9.0).</p>
  
  <p>get exception:</p>
  
  <pre><code>java.security.KeyStoreException: Failed to store private key
      at android.security.keystore.AndroidKeyStoreSpi.setPrivateKeyEntry(AndroidKeyStoreSpi.java:536)
      at android.security.keystore.AndroidKeyStoreSpi.engineSetKeyEntry(AndroidKeyStoreSpi.java:278)
      at java.security.KeyStore.setKeyEntry(KeyStore.java:1179)
  ...
  
  Caused by: android.security.KeyStoreException: Memory allocation failed
      at android.security.KeyStore.getKeyStoreException(KeyStore.java:851)
      ... 19 more
  </code></pre>
  
  <p>please addvice</p>