Skip to main content

Create a Keypair

This snippet demonstrates how your mobile apps can generate the private and public key. The private key is automatically saved to your app's Keychain. The snippet also shows how the public key is exported, and how to delete the private key from the Keychain.

Prerequisites

Steps

  1. Add a new Swift file to your project, and copy the following code snippet:
// Create the private and public keys.
KeychainHelper.create("sample")
{
    success, publicKeyData  in

    // Export the public key
    if success && let data = publicKeyData
    {
        print("Public key: \(KeychainHelper.export(data)!)")
    }
}

// Delete the private key.
KeychainHelper.delete("sample")
{
    result in
    
    print("Private key deleted successful: \(result).")
}
    

Next Steps

You have now successfully generated private and public keys, exported the public key, and deleted the private key, by using the IBMVerifyKit framework.

For a more in-depth sample on public and private keys, have a look at the Secure key sample under the Samples section. Furthermore, play around with other samples which demonstrate further functionality of the framework in the Samples section, or have a look at more quick, easy-to-implement code snippets in the Snippets section.