考虑到SecKey,有什么方法可以推断其类型(例如,是kSecAttrKeyTypeRSA
还是kSecAttrKeyTypeEC
)?
我看到了SecKeyGetTypeID(),但是我不清楚此函数在什么参数上运行,因为它不接受任何参数。
答案 0 :(得分:2)
您可以从密钥中检索kSecAttrKeyType
,并检查它是否为kSecAttrKeyTypeRSA
(或kSecAttrKeyTypeEC
)。示例(摘自SwiftyRSA):
func isRSAKey(seckey: SecKey) -> Bool {
guard let attributes = SecKeyCopyAttributes(seckey) as? [CFString: Any],
let keyType = attributes[kSecAttrKeyType] as? String else {
return false
}
let isRSA = keyType == (kSecAttrKeyTypeRSA as String)
return isRSA
}