Java 获取Mac OS的私钥
我正在尝试从密钥链中检索私钥,以便稍后进行数字签名 使用下面的代码,我可以访问智能卡和本地驱动器中的所有证书,但不能访问私钥。我在智能卡中有许多私钥和证书对Java 获取Mac OS的私钥,java,macos,itext,smartcard,private-key,Java,Macos,Itext,Smartcard,Private Key,我正在尝试从密钥链中检索私钥,以便稍后进行数字签名 使用下面的代码,我可以访问智能卡和本地驱动器中的所有证书,但不能访问私钥。我在智能卡中有许多私钥和证书对 KeyStore keyStore = KeyStore.getInstance("KeychainStore", "Apple"); keyStore.load(null, "-".toCharArray()); Enumeration<String> aliases = keyStore.aliases(); whil
KeyStore keyStore = KeyStore.getInstance("KeychainStore", "Apple");
keyStore.load(null, "-".toCharArray());
Enumeration<String> aliases = keyStore.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
if (keyStore.isKeyEntry(alias)) {
try {
PrivateKey key = (PrivateKey) keyStore.getKey(alias, "-".toCharArray());
}
catch (RuntimeException e) {
System.out.println(" Key failed to load ("+e.getMessage()+")");
}
Certificate certificate = keyStore.getCertificate(alias);
String subject = "";
if ((certificate != null) && (certificate instanceof X509Certificate)) {
subject =((X509Certificate)certificate).getSubjectX500Principal().getName();
}
}
}
keystorekeystore=KeyStore.getInstance(“KeychainStore”、“Apple”);
load(null,“-”.toCharArray());
枚举别名=keyStore.alias();
while(别名.hasMoreElements()){
字符串别名=别名。nextElement();
if(keyStore.isKeyEntry(别名)){
试一试{
PrivateKey=(PrivateKey)keyStore.getKey(别名“-”.toCharArray());
}
捕获(运行时异常e){
System.out.println(“未能加载密钥(“+e.getMessage()+”));
}
证书证书=keyStore.getCertificate(别名);
字符串主语=”;
if((证书!=null)和&(X509Certificate的证书实例)){
subject=((X509Certificate)证书).getSubjectX500Principal().getName();
}
}
}
如何从特定证书检索私钥getKey()
总是返回空值,只有一个系统私钥除外