Code example for KeyFactory

Methods: generatePublic

0
		FileInputStream fis = new FileInputStream(keyFilePath);
		byte[] encodedKey = new byte[fis.available()];
		fis.read(encodedKey);
		fis.close();
		X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(encodedKey);
		return keyFactory.generatePublic(publicKeySpec);
	} 
 
	/** 
	 * This function is responsible for retrieving a private key from the specified private key file path 
	 * @param keyFilePath 
	 * @return 
	 * @throws Exception 
	 */ 
	public PrivateKey getPrivateKey(String keyFilePath) throws Exception {
		FileInputStream fis = new FileInputStream(keyFilePath);
		byte[] encodedKey = new byte[fis.available()];
		fis.read(encodedKey);
		fis.close();
		PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(encodedKey);