p12 データから有効期限を抽出しようとしています。Apple のドキュメントを最初から最後まで読みましたが、その方法を見つけることができませんでした - 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で同じことをする方法を知っている人はいますか?
編集: Apple フォーラムの質問も添付して ください https://forums.developer.apple.com/message/53696#53696 ありがとう