java.security.KeyStore类的isCertificateEntry()方法用于检查此KeyStore实例中是否存在指定的Certificate条目。它返回一个表示相同值的布尔值。
用法:
public final boolean isCertificateEntry(String alias) throws KeyStoreException
参数:此方法接受别名的名称作为要检查其证书条目的参数。
返回值:此方法检查是否存在所请求别名的证书条目,如果存在,则返回布尔值。
异常:如果 key 库尚未初始化,则此方法将引发KeyStoreException。
注意:由于不存在“ privatekey” key 库,因此本文中的所有程序都无法在在线IDE上运行。您可以在系统上的Java编译器上检查此代码。要检查此代码,请在系统上创建 key 库“ privatekey”,并设置自己的 key 库密码以访问该 key 库。
下面是说明isCertificateEntry()方法的示例:
示例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
// and getting instance
// By usng getInstance() method
KeyStore sr = KeyStore.getInstance("JKS");
// keystore password is required to access keystore
char[] pass = ("123456").toCharArray();
// creating and initializing object of InputStream
InputStream is
= new FileInputStream(
"f:/java/private key.store");
// 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)
System.out.println(
"\nCertificate "
+ "entry is present");
else
System.out.println(
"\nCertificate "
+ "entry is not present");
}
catch (NoSuchAlgorithmException e) {
System.out.println("Exception thrown : " + e);
}
catch (NullPointerException e) {
System.out.println("Exception thrown : " + e);
}
catch (KeyStoreException e) {
System.out.println("Exception thrown : " + e);
}
catch (FileNotFoundException e) {
System.out.println("Exception thrown : " + e);
}
catch (IOException e) {
System.out.println("Exception thrown : " + e);
}
catch (CertificateException e) {
System.out.println("Exception thrown : " + e);
}
}
}
示例2:对于KeyStoreException
// 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
// and getting instance
// By usng getInstance() method
KeyStore sr = KeyStore.getInstance("JKS");
// keystore password is required to access keystore
char[] pass = ("123456").toCharArray();
// creating and initializing object of InputStream
InputStream is
= new FileInputStream(
"f:/java/private key.store");
// 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)
System.out.println(
"\nCertificate "
+ "entry is present");
else
System.out.println(
"\nCertificate "
+ "entry is not present");
}
catch (NullPointerException e) {
System.out.println("Exception thrown : " + e);
}
catch (KeyStoreException e) {
System.out.println("Exception thrown : " + e);
}
catch (FileNotFoundException e) {
System.out.println("Exception thrown : " + e);
}
}
}
相关用法
- Java KeyStore getCertificate()用法及代码示例
- Java KeyStore containsAlias()用法及代码示例
- Java KeyStore getEntry()用法及代码示例
- Java KeyStore deleteEntry()用法及代码示例
- Java KeyStore getCertificateAlias()用法及代码示例
- Java KeyStore getProvider()用法及代码示例
- Java KeyStore getKey()用法及代码示例
- Java KeyStore getType()用法及代码示例
- Java KeyStore getCreationDate()用法及代码示例
- Java KeyStore isKeyEntry()用法及代码示例
- Java KeyStore getCertificateChain()用法及代码示例
- Java KeyStore aliases()用法及代码示例
- Java KeyStore getDefaultType()用法及代码示例
- Java Java lang.Long.builtcount()用法及代码示例
注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 KeyStore isCertificateEntry() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。