我从给定的证书中获得了一个 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 algorithm id: 1, key type: RSAPublicKey, version: 4, block size: 2048 bits, exponent: {hex: 10001, decimal: 65537}, modules: , addr: 0x7f7fba5arerw34,其中它特别说明了它的类型为 RSAPublicKey。
有没有办法获得使用的加密类型?