Ahah I've found the solution, sorry about this!
The problem was caused due to an exception being thrown earlier that I missed which meant the keyStore would never be saved. On Feb 8, 1:14 am, Reado <[email protected]> wrote: > I have some code for my app that creates akeystorein android, > creates some default keys then saves thekeystore. > > Later on the code tries to reload thekeystore, on the emulator this > runs fine however when run on a phone I get an EOFException. Any > advice on where I'm going wrong? > > An out take of the code is below: > > In the class I have the following variables > > staticKeyStorekeyStore; > String filenameKeyStore = "KeyStore.kstore"; > > Then the following two functions > > public KeyHandler(Context context) { > > if(keyStore== null) { > Log.d("KeyStore", "Keystoreis null so loading"); > if(initialiseKeyStore(context) == false) { > //KeyStorefailed to initialise > Log.e("ERROR", "Store failed to initialise"); > } > } > } > > private boolean initialiseKeyStore(Context context) { > FileInputStream input = null; > try { > // Get an instance ofKeyStore > keyStore=KeyStore.getInstance("BKS"); > > // Load theKeyStorefile > try { > > // Try and open the private key store > input = > context.openFileInput(filenameKeyStore); > > } catch (FileNotFoundException e) { > > // If the file doesn't exist then create the > file, a ECDH key and > store the key > Log.w("Warning","File does not exist, > creating new file"); > > try { > // Load the default Key Store > keyStore.load(null, null); > > // Create the file > FileOutputStream output = > context.openFileOutput(filenameKeyStore, 0); > > // Reset private key > resetPrivateKey(context); > > // Save the key > keyStore.store(output, > "password".toCharArray()); > > // Close thekeystoreand set the input > stream > output.close(); > input = > context.openFileInput(filenameKeyStore); > > // Reset thekeyStore > keyStore=KeyStore.getInstance("BKS"); > > } catch (FileNotFoundException ee) { > Log.e("ERROR", "File not found, even > though we just created it"); > return false; > } catch (NoSuchProviderException e1) { > // BC isn't working exit > e1.printStackTrace(); > System.exit(1); > } catch (InvalidAlgorithmParameterException > e1) { > Log.e("ERROR", "The algorithm used > for secure algorithm is > incorrect"); > e1.printStackTrace(); > return false; > } > } > > // Load the store > keyStore.load(input, "password".toCharArray()); > > } catch (KeyStoreException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > return false; > } catch (CertificateException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > return false; > } catch (EOFException e) { > > // Where the exception is caught > > e.printStackTrace(); > return false; > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > return false; > } catch (NoSuchAlgorithmException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > return false; > } catch (NoSuchProviderException e) { > // Serious error, return > e.printStackTrace(); > System.exit(1); > } > > return true; > } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

