【问题标题】:Key generation failed iOS 15 simulator Xcode13密钥生成失败 iOS 15 模拟器 Xcode13
【发布时间】:2022-08-22 20:23:51
【问题描述】:

Error Domain=NSOSStatusErrorDomain Code=-4 \"Key generation failed, error -4\" UserInfo={numberOfErrorsDeep=0, NSDescription=Key generation failed, error -4} 在创建私钥期间

let tag = \"com.qwerty.www\".data(using: .utf8)!
        
        let attributes: [String: Any] =
            [kSecAttrKeyType as String : type(of: kSecAttrKeyType),
             kSecAttrKeySizeInBits as String:      2048,
             kSecPrivateKeyAttrs as String:
                [kSecAttrIsPermanent as String:    true,
                 kSecAttrApplicationTag as String: tag]
        ]
        
        var error: Unmanaged<CFError>?
        guard let privateKey = SecKeyCreateRandomKey(attributes as CFDictionary, &error) else {
            print(error!.takeRetainedValue() as Error)
            return
        }
        
        let publicKey = SecKeyCopyPublicKey(privateKey)

    标签: ios swift xcode rsa


    【解决方案1】:

    在属性中

    kSecAttrKeyType as String : type(of: kSecAttrKeyType)

    我应该指出kSecAttrKeyType 的类型,例如kSecAttrKeyTypeRSA 或其他类型。

    【讨论】:

      猜你喜欢
      • 2015-07-18
      • 2016-04-09
      • 1970-01-01
      • 1970-01-01
      • 2012-05-30
      • 2020-05-15
      • 1970-01-01
      • 2021-05-08
      • 1970-01-01
      相关资源
      最近更新 更多