Code example for PrivateKey

Methods: getEncoded

0
		fos.write(x509EncodedKeySpec.getEncoded());
		fos.close();
  
		// Store Private Key. 
		PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(
				privateKey.getEncoded());
		fos = new FileOutputStream(path + "/private.key");
		fos.write(pkcs8EncodedKeySpec.getEncoded());
		fos.close();
	} 
  
	public KeyPair LoadKeyPair(String path, String algorithm)
			throws IOException, NoSuchAlgorithmException, 
			InvalidKeySpecException { 
		// Read Public Key. 
		InputStream fis = getClass().getResourceAsStream("/chaves/public.key");
		byte[] encodedPublicKey =  IOUtils.toByteArray(fis);
		fis.close();
  
		// Read Private Key. 
		fis = getClass().getResourceAsStream("/chaves/private.key");