2

This question is addition to my previous question How to import RSA private key, which generated by openssl, into AndroidKeyStore. I try to import my privateKey in KeyStore by the following way:

KeyStore ks = KeyStore.getInstance("AndroidKeyStore");
ks.load(null);
ks.setKeyEntry("myAlias", prKey, null, new Certificate[] {cert});

and I get an exception:

"java.lang.NullPointerException: Attempt to get length of null array"

And it is strange, because

  1. prKey.getAlgorithm() return correct algorithm.
  2. cert.getPublicKey().getAlgorithm() also return correct algorithm.
  3. ks.size() works correctly.

Key and Certificate were generated by:

openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days XXX
openssl x509 -outform der -in cert.pem -out certificate.der
xxd -p certificate.der

So, think all parameters are correct, but why is it throw the exception?

Community
  • 1
  • 1
i716
  • 139
  • 1
  • 1
  • 5
  • 1
    * Please provide a full stack trace, including cause stack traces. * Please provide the code illustrating how the PrivateKey instance being imported was obtained. – Alex Klyubin Apr 27 '16 at 16:48
  • I've noticed there are some weird interactions with the Android KeyStore on occassion. For example, [AndroidKeyStoreRSAPrivateKey cannot be cast to RSAPrivateKey](http://stackoverflow.com/q/36305043) and [Crash casting AndroidKeyStoreRSAPrivateKey to RSAPrivateKey](http://stackoverflow.com/q/32400689). – jww Apr 27 '16 at 21:23
  • > "Please provide a full stack trace, including cause stack traces". thank you for support, but I cannot insert stack trace. – i716 Jun 10 '16 at 10:17

0 Answers0