Provides Advanced Encryption Standard (AES)
capabilities.
- Relies on native
CCCrypt
(viaimport CommonCrypto
). - Uses
Cipher Block Chaining (CBC)
mode with randomInitialization Vector (IV)
. - Works (only) with 256-bit
key size
. This is by design. - Uses
kCCOptionPKCS7Padding
asCCOptions
by default.
(More on the topic from WWDC 2019: Adopting Swift Packages in Xcode and Creating Swift Packages.)
In your Package.swift
, add AESCryptable
as a dependency:
dependencies: [
// π AES encryption/decryption with random iv. Swift 5 and up.
.package(url: "https://github.com/backslash-f/aescryptable", from: "1.0.0")
],
Associate the dependency with your target:
targets: [
.target(name: "App", dependencies: ["AESCryptable"])
]
Run: swift build
import AESCryptable
do {
// encrypt
let aes = try AES(keyString: "01234567890123456789012345678901")
let encryptedData = try aes.encrypt("The black knight always triumphs!")
// decrypt
let decryptedString = try aes.decrypt(encryptedData)
print(decryptedString) // The black knight always triumphs!
} catch {
print(error)
}
(Refer to the test class for a high-level overview.)
Clone the repo and use AESCryptable.playground
to see the code in action: