SecceyGeneratePair在xctest中

时间:2018-03-28 07:02:18

标签: swift cocoa-touch keychain security.framework

func generateSecureKeyPair() -> Bool {
        var pubKey, privKey: SecKey?

        let privateKeyParams: [String: AnyObject] = [
            kSecAttrIsPermanent as String: true as AnyObject,
            kSecAttrApplicationTag as String: KeyTag.PrivateKey.rawValue as AnyObject
        ]

        // private key parameters
        let publicKeyParams: [String: AnyObject] = [
            kSecAttrIsPermanent as String: true as AnyObject,
            kSecAttrApplicationTag as String: KeyTag.PublicKey.rawValue as AnyObject
        ]

        // global parameters for our key generation
        let parameters: [String: AnyObject] = [
            kSecAttrKeyType as String: kSecAttrKeyTypeRSA,
            kSecAttrKeySizeInBits as String:    kKeySize as AnyObject,
            kSecPublicKeyAttrs as String:       publicKeyParams as AnyObject,
            kSecPrivateKeyAttrs as String:      privateKeyParams as AnyObject,
            ]


        let status = SecKeyGeneratePair(parameters as CFDictionary, &pubKey, &privKey)
        print("keypair status >>> \(status)")
        if status != errSecSuccess {
            return false
        }
        return true
    }

我在cocoa touch框架中使用SecKeyGeneratePair生成publicKey和privateKey。

但是当我尝试测试方法时,它总是返回

  

OSStatus -50

我甚至无法添加钥匙串共享权利,因为它在框架中不支持。

0 个答案:

没有答案