1024programmer Java KeyStoreisCertificateEntry() method in Java, example

KeyStoreisCertificateEntry() method in Java, example

KeyStore isCertificateEntry() method in Java, examples

Original text: https://www . geesforgeks . org/keystore-iscertifientry-method-in-Java-with-examples/

The isCertificateEntry() method of the java.security.KeyStore class is used to check whether the specified certificate entry exists in this KeyStore instance. It returns a boolean value representing the same.

Syntax:

public final boolean isCertificateEntry(String alias)
throws KeyStoreException

Parameters:This method accepts alias The name of the parameter whose certificate entry is to be checked.

Return Value: This method checks whether the certificate entry for the requested alias exists and returns a Boolean value.

Exception: If the keystore has not been initialized, this method throws KeystoreException.

Note: None of the programs in this article will run on the online IDE because the “privatekey” keystore does not exist. You can inspect this code on your system’s Java compiler. To check this code, create a keystore “privatekey” on your system and set your own keystore password to access the keystore.

The following is an example illustrating the iscertificientry() method:

Example 1:

// Java program to demonstrate getCertificate() method
import java.security.*;
import java.security.cert.*;
import java. util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
 {
 try {
                                                                         creating the object of KeyStore
                                                                                                                                                                                              span>
 KeyStore sr = KeyStore.getInstance("JKS");
 // keystore password is required to access keystore
          char[] pass = ("123456").toCharArray();
   // creating and initializing object of InputStream
                                                                                         >new FileInputStream(
                                                   key.store");
 // initializing keystore object
 sr.load(is, pass);
                                                                                                                    class="n">Boolean status
 = sr.isCertificateEntry( "ftpkey");
 // display the result
 if (statusclass GFG {
 public static void main (String[] argv)
 {
 try {
 // creating the object of KeyStore
 // and getting instance
 // By using getInstance() method
  KeyStore sr = KeyStore.getInstance("JKS");
                                                                 ">// keystore password is required to access keystore
 char[] pass = ("123456").toCharArray();
   // creating and initializing object of InputStream
                                                                                          "o">= new FileInputStream(
                                                                                                 / initializing keystore object
 // sr.load(is, pass);
 // checking the presence of certificate entry
 // using isCertificateEntry() method
 Boolean status
 = sr. isCertificateEntry("ftpkey") ;
 // display the result
 if ( status)
                                              "p">.out.println(
 "\nCertificate "
 + "entry is present");
                                                                           "n">System.out.println(
                                                                                               "o">+ "entry is not present");
 }
 catch (NullPointerException e) {
   System .out.println("Exception thrown : " + e);
 }
 catch (KeyStoreException e) {
                                                    span>out.println( "Exception thrown : " + e);
 }
 catch (FileNotFoundException e) {
 System.out .println("Exception thrown : " + e);
 }
 }
}

Output:

Reference:https://docs.Oracle.com/javase/9/docs/API/Java/security/keystore. html # iscertifieteentry-Java . lang . string-

pan class=”na”>println(“Exception thrown : “ + e);
 }
}
}

Output:

Reference: https://docs . Oracle . com/javase/9/docs/API/Java/security/keystore . html #iscertifieteentry-Java . lang . string-

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/keystoreiscertificateentry-method-in-java-example/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: 34331943@QQ.com

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索