private static KeySpec decryptPrivateKey(final byte[] encryptedPrivateKey) throws GeneralSecurityException {
  EncryptedPrivateKeyInfo epkInfo;
  try {
    epkInfo=new EncryptedPrivateKeyInfo(encryptedPrivateKey);
  }
 catch (  final IOException ex) {
    return null;
  }
  final String pass="android";
  final char[] password=pass.toCharArray();
  final SecretKeyFactory skFactory=SecretKeyFactory.getInstance(epkInfo.getAlgName());
  final Key key=skFactory.generateSecret(new PBEKeySpec(password));
  final Cipher cipher=Cipher.getInstance(epkInfo.getAlgName());
  cipher.init(Cipher.DECRYPT_MODE,key,epkInfo.getAlgParameters());
  try {
    return epkInfo.getKeySpec(cipher);
  }
 catch (  final InvalidKeySpecException ex) {
    Log.e(TAG,"Password for keyFile may be bad.",ex);
    return null;
  }
}

private static KeySpec decryptPrivateKey ( final byte [ ] encryptedPrivateKey ) throws GeneralSecurityException { EncryptedPrivateKeyInfo epkInfo ; try { epkInfo = new EncryptedPrivateKeyInfo ( encryptedPrivateKey ) ; } catch ( final IOException ex ) { return null ; } final String pass = "android" ; final char [ ] password = pass . toCharArray ( ) ; final SecretKeyFactory skFactory = SecretKeyFactory . getInstance ( epkInfo . getAlgName ( ) ) ; final Key key = skFactory . generateSecret ( new PBEKeySpec ( password ) ) ; final Cipher cipher = Cipher . getInstance ( epkInfo . getAlgName ( ) ) ; cipher . init ( Cipher . DECRYPT_MODE , key , epkInfo . getAlgParameters ( ) ) ; try { return epkInfo . getKeySpec ( cipher ) ; } catch ( final InvalidKeySpecException ex ) { Log . e ( TAG , "Password for keyFile may be bad." , ex ) ; return null ; } }
decrypt an encrypted pkcs 8 format private key . based on ghstark ' s post on aug 6 , 2006 at http : / / forums . sun . com / thread . jspa ? threadid = 758133 & messageid = 4330949
