How could you load a public or private key from a file, and then encrypt or decrypt data with it in Swift while using no libraries or APIs?
You could use OS X’s built-in OpenSSL to generate and encrypt or a combo of OS X and Swift.
In the end, the important files from an iOS standpoint are publicKey.der and privateKey.pfx. You will use publicKey.der to encrypt data, and privateKey.pfx to decrypt.
Encryption in iOS
In iOS, in addition to providing support functions for encoding and decoding keys, the Certificate, Key, and Trust Services API also provides basic encryption, decryption, signing, and verifying of blocks of data using the following SecKey functions:
SecKeyEncrypt—encrypts a block of data using the specified key.
SecKeyDecrypt—decrypts a block of data using the specified key.
SecKeyRawSign—signs a block of data using the specified key.
SecKeyRawVerify—verifies a signature against a block of data and a specified key.
Encrypting and Hashing Data
You can find examples of how to use these functions in Apple docs Certificate, Key, and Trust Services Tasks for iOS
import UIKit import CoreFoundation
Use a bridging header file for Security.h