VOOZH about

URL: https://www.geeksforgeeks.org/java/keystore-getentry-method-in-java-with-examples/

⇱ KeyStore getEntry() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

KeyStore getEntry() method in Java with Examples

Last Updated : 7 Feb, 2023

The getEntry() method of java.security.KeyStore class is used to get the keystore entry for this instance with the help of the specified alias and the protection parameter. 

Syntax:

public final KeyStore.Entry
 getEntry(String alias, 
 KeyStore.ProtectionParameter protParam)
 throws NoSuchAlgorithmException, 
 UnrecoverableEntryException, 
 KeyStoreException

Parameter: This method accepts following arguments as a parameter.

  • alias: which is name of the Keystore Entry to be fetched.
  • protParam: which contains the password to access keystore.

Return Value: This method returns the keystore entry for the requested alias if it exists. 

Exception: This method throws following exception

  • NullPointerException: for null alias.
  • NoSuchAlgorithmException: if the algorithm is missing.
  • UnrecoverableEntryException: if the specified password is invalid.
  • KeyStoreException: if the keystore has not been initialized (loaded).

Note: All the programs in this article won’t run on online IDE as no ‘privatekey’ Keystore exists. You can check this code on Java compiler on your system. To check this code, create a Keystore ‘privatekey’ on your system and set your own Keystore password to access that Keystore.

Below are the examples to illustrate the getEntry() method: 

Example 1: 

Output: 👁 Image

Example 2: For KeyStoreException 

Comment