Code example for PKCS8EncodedKeySpec

0
    	if(!isAuthenticated()) return null; 
    	 
		byte[] keyBytes = getKeyFileBytes(context, PRIVATE_KEY_FILENAME);
    	byte[] pk = decryptPrivateKey(keyBytes);
		 
    	PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(pk);
		KeyFactory kf = KeyFactory.getInstance(KEY_EXCHANGE_PROTOCOL);
		PrivateKey privateKey = kf.generatePrivate(spec);
    	 
    	return privateKey;
    } 
     
     
    public static void writePrivateKey(Context context, PrivateKey pk) throws Exception {
    	FileOutputStream privOut = context.openFileOutput(PRIVATE_KEY_FILENAME, Context.MODE_PRIVATE);
    	 
    	privOut.write(encryptPrivateKey(pk));
		 
		privOut.flush();
        privOut.close();
Stop searching for code, let great code find you!  Add Codota to your java IDE