指定された証明書から SecKey を取得します。証明書に応じて、SecKey は RSA または EllipticCurve 暗号化を使用できます。
let certificate = SecCertificateCreateWithData(kCFAllocatorDefault, certificateData)
let certArray = [ certificate ]
let policy = SecPolicyCreateBasicX509()
var optionalTrust: SecTrust?
let status = SecTrustCreateWithCertificates(certArray as AnyObject, policy, &optionalTrust)
if status == errSecSuccess {
let publicKey = SecTrustCopyPublicKey(optionalTrust!)
print(publicKey!)
}
publicKey を出力すると、SecKeyRef アルゴリズム ID: 1、キー タイプ: RSAPublicKey、バージョン: 4、ブロック サイズ: 2048 ビット、指数: {hex: 10001、10 進数: 65537}、モジュラス: 、addr: 0x7f7fba5arerw34 が得られます。具体的には、タイプ RSAPublicKey であると述べています。
使用されている暗号化の種類を取得する方法はありますか?