Search code examples
android-keystore

Android KeyStore error codes


I'm using Android KeyStore implementation, and getting an exception trying to setEntry: java.security.KeyStoreException: Failed to import secret key. Keystore error code: -6

Does anyone know where I can get information about these error codes? What exactly do they mean?

I have tried to decompile, but could not get the source code. Found the class here AndroidKeyStoreSpi, but it does not seem to be the right one, since line numbers do not match, and it does not help much either as it refers to a method called "importKey", which does not exist in the KeyStore class (or at least in the one I found documented).

Any help will be appreciated!


Solution

  • This looks like an error code from the underlying Keymaster (the secure hardware abstraction layer API). The error codes are found in KeymasterDefs.java. In this particular case, -6 is KM_ERROR_UNSUPPORTED_KEY_SIZE, which means you must have tried to import a key of an unsupported size. I know it's been a long time, but do you recall what size key you were trying to import, and what algorithm?