我正在尝试从 p12 数据中提取到期日期。我从头到尾阅读了苹果文档,但无法找到如何去做 - https://developer.apple.com/library/prerelease/mac/documentation/Security/Conceptual/CertKeyTrustProgGuide/CertKeyTrustProgGuide.pdf
我在pdf中的代码,我正在使用带有私钥p12数据的NSData加载SecKeyRef,并且能够解密在服务器上加密的数据。
问题是我试图阻止在 p12 过期时进行解密,但我无法检测到密钥何时过期。
在java上,解决方案非常简单
private PrivateKey decodeP12Key(String key) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException, UnrecoverableKeyException,InvalidKeyException {
KeyStore kStore = KeyStore.getInstance(KeyType.P12.getKeyValue());
String[] words = key.split(" ");
return null;
}
X509Certificate cert = (X509Certificate)kStore.getCertificate(alias);
if(isExpired(cert)){
throw new InvalidKeyException("Invalid key used, please check if your key is valid and not expired");
}
PrivateKey pKey = (PrivateKey)kStore.getKey(alias,"".toCharArray());
return pKey;
cipher.init(Cipher.DECRYPT_MODE, key);
return cipher;
}
private boolean isExpired(X509Certificate cert){
Date expirationDate = cert.getNotAfter();
Date beginDate = cert.getNotBefore();
Date currentDate = new Date(System.currentTimeMillis());
return currentDate.after(expirationDate) || currentDate.before(beginDate);
}
任何人都知道如何在 ios 上做同样的事情?
编辑:还附上苹果论坛上的问题 https://forums.developer.apple.com/message/53696#53696 谢谢