Code example for PrivateKey

Methods: getEncoded

0
		FileOutputStream fos = new FileOutputStream(dirPath + "/public.key");
		fos.write(x509EncodedKeySpec.getEncoded());
		fos.close();
		 
		// Store Private Key. 
		PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(privateKey.getEncoded());
		fos = new FileOutputStream(dirPath + "/private.key");
		fos.write(pkcs8EncodedKeySpec.getEncoded());
		fos.close();
	} 
 
	/** 
	 * This function is responsible for retrieving a public key from the specified public key file path 
	 * @param keyFilePath 
	 * @return 
	 * @throws Exception 
	 */ 
	public PublicKey getPublicKey(String keyFilePath) throws Exception {
		FileInputStream fis = new FileInputStream(keyFilePath);
		byte[] encodedKey = new byte[fis.available()];
		fis.read(encodedKey);