【发布时间】:2018-08-30 16:31:22
【问题描述】:
目前我正在我的 iOS 应用程序中成功生成椭圆曲线密钥对:
let privateKeyParams: [String: Any] = [
kSecAttrIsPermanent as String: true,
kSecAttrApplicationTag as String: privateTag
]
let publicKeyParams: [String: Any] = [
kSecAttrIsPermanent as String: true,
kSecAttrApplicationTag as String: publicTag,
kSecAttrAccessible as String: kSecAttrAccessibleAlways
]
let query: [String: Any] = [
kSecAttrKeyType as String: kSecAttrKeyTypeECSECPrimeRandom,
kSecPrivateKeyAttrs as String: privateKeyParams,
kSecPublicKeyAttrs as String: publicKeyParams,
kSecAttrKeySizeInBits as String: 256 as AnyObject,
]
let status = SecKeyGeneratePair(query as CFDictionary, &self.publicKey, &self.privateKey)
guard status == errSecSuccess else {
print("Could not generate keypair")
return
}
guard let pubKey = self.publicKey, let privKey = self.privateKey else {
print("Keypair null")
return
}
这很有效,因为当我检查我的密钥是否存在时,它们确实存在,而且我还可以加密/解密和签名/验证。
Soo.. 在下一步中,我需要生成一个 SecCertificate,它将基本上保存我的公钥...这只是一个要求。
但是实际上没有关于如何执行此操作的 API/文档。我看到的唯一 api 是关于如何从现有的 der 文件等生成 SecCertificate。
所以我的问题是:
如何从现有的椭圆曲线密钥对 (SecKey) 生成 SecCertificate 对象?
谢谢和问候!
【问题讨论】:
标签: swift cryptography certificate elliptic-curve key-pair