Dhruv
Dhruv

Reputation: 2163

SecKeyGeneratePair in xctest

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
    }

I'm generating publicKey and privateKey using SecKeyGeneratePair in cocoa touch framework.

But when I try to test the method, it always return

OSStatus -50

I cannot even add keychain sharing entitlements as it doesn't support in framework.

Upvotes: 1

Views: 121

Answers (0)

Related Questions