小编Gok*_*kul的帖子

如何从 iOS 钥匙串中存储的密钥获取 DER 格式的公钥?

我正在使用以下代码创建密钥

let tag = "com.example.keys.mykey".data(using: .utf8)!
let attributes: [String: Any] =
[kSecAttrKeyType as String:            kSecAttrKeyTypeECSECPrimeRandom,
 kSecAttrKeySizeInBits as String:      256,
 kSecPrivateKeyAttrs as String:
    [kSecAttrIsPermanent as String:    true,
     kSecAttrApplicationTag as String: tag]]
guard let privateKey = SecKeyCreateRandomKey(attributes as CFDictionary, &error) else {
throw error!.takeRetainedValue() as Error}
Run Code Online (Sandbox Code Playgroud)

使用获取公钥

let publicKey = SecKeyCopyPublicKey(privateKey)
Run Code Online (Sandbox Code Playgroud)

security keychain public-key ios swift

5
推荐指数
1
解决办法
1973
查看次数

标签 统计

ios ×1

keychain ×1

public-key ×1

security ×1

swift ×1