SwCrypt uses dlopen and dlsym to load the CommonCrypto’s functions, because not all of them are available in public header files. You have to check the availability before using them.
let digestAvailable : Bool = CC.digestAvailable()
let ramdomAvailable : Bool = CC.randomAvailable(()
let hmacAvailable : Bool = CC.hmacAvailable()
let cryptorAvailable : Bool = CC.cryptorAvailable
let keyDerivationAvailable : Bool = CC.KeyDerivation.available()
let keyWrapAvailable : Bool = CC.KeyWrap.available()
let rsaAvailable : Bool = CC.RSA.available()
let dhAvailable : Bool = CC.DH.available()
let ecAvailable : Bool = CC.EC.available()
let crcAvailable : Bool = CC.CRC.available()
let cmacAvailable : Bool = CC.CMAC.available()
let gcmAvailable : Bool = CC.GCM.available()
let ccmAvailable : Bool = CC.CCM.available()
or all in one turn:
let ccAvailable : Bool = CC.available()
SwCrypt
Create public and private RSA keys in DER format
Convert them to PEM format
Or read them from strings with PEM data
Or encrypt, decrypt the private key (OpenSSL compatible)
Get public key from private keys in DER format
Encrypt, decrypt data with RSA
Sign, verify data with RSA
Elliptic curve functions
Diffie-Hellman functions
Encrypt, decrypt data with symmetric ciphers
Encrypt, decrypt data with symmetric authenticating ciphers
Digest functions
HMAC function
CMAC function
CRC function
KeyDerivation
Symmetric Key Wrapping
Upsert, get, delete keys from KeyStore
Check availability
SwCrypt uses dlopen and dlsym to load the CommonCrypto’s functions, because not all of them are available in public header files. You have to check the availability before using them.
Install
Just copy SwCrypt.swift to your project or use the Carthage dependency manager.
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. To install SwCrypt with CocoaPods:
Make sure CocoaPods is installed.
Update your Podfile to include the following:
Run
pod install
.Swift Package Manager
SPM is built into new versions of Xcode. To install SwCrypt with SPM:
Open your project in Xcode
Click “File” -> “Swift Packages” -> “Add Package Dependency…”
Paste the following URL: https://github.com/soyersoyer/SwCrypt
Click “Next” -> “Next” -> “Finish”
Inspired from
License
This project is copyrighted under the MIT license.