The most convenient, simple & lightweight Swift 2 framework to encrypt / decrypt a string with AES-256 CBC encryption.
AES256CBC is meant as simple, stand-alone file to bring AES-256 Cipher Block Chaining encryption to any Swift 2 powered app without any friction or learning curve. It is used in multiple projects of SwiftyBeaver and was developed in cooperation with Marcin Krzyżanowski from CryptoSwift.
AES256CBC alternatives and similar libraries
Based on the "Cryptography" category.
Alternatively, view AES256CBC alternatives based on common mentions on social networks and blogs.
9.2 1.4 AES256CBC VS RNCryptorCCCryptor (AES encryption) wrappers for iOS and Mac in Swift. -- For ObjC, see RNCryptor/RNCryptor-objc
7.7 7.9 L3 AES256CBC VS ThemisEasy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.
4.3 0.0 L2 AES256CBC VS BlueCryptorSwift cross-platform crypto library using CommonCrypto/libcrypto
4.1 0.7 L3 AES256CBC VS SiphashSimple and secure hashing in Swift with the SipHash algorithm
4.0 3.1 AES256CBC VS JOSESwiftA framework for the JOSE standards JWS, JWE, and JWK written in Swift.
3.7 0.9 AES256CBC VS BlueRSARSA public/private key encryption, private key signing and public key verification in Swift using the Swift Package Manager. Works on iOS, macOS, and Linux (work in progress).
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of AES256CBC or a related project?
AES256CBC Encryption for Swift 2, 3, 4 & 5
The most convenient & lightweight AES256 Encryption Framework for Swift 3, 4 & 5 which even works under Linux. For Swift 2 use tag 0.1.1.
Unique Feature Set
- Just a single file in pure Swift 4 & 5 source code
- Runs natively on iOS, macOS, tvOS & watchOS & Linux
- No additional dependencies or header files
- Maximum convenience for encrypting / decrypting of strings
- Built-in generating of compatible 32 character password
- Automatic string padding
- Automatic handling & embedding of a random initialisation vector
Please follow SwiftyBeaver on Twitter to stay up-to-date on new versions.
- iOS 8.0+, macOS X 10.9+, tvOS 9+, watchOS 2+, Linux, Docker
- Xcode 7+
You can use Carthage to install AES256CBC by adding that to your Cartfile:
To use CocoaPods just add this to your Podfile:
via Swift Package Manager
To use AES256CBC as a Swift Package Manager package just add the following to your Package.swift file’s dependencies.
- Download the latest release zip from here
- Drag & drop the
/sourcesfolder into your project (make sure "Copy items if needed" is checked)
- Rename the "sources" group to "AES256CBC" if you'd like
Note: You don't have to
import AES256CBC if you install this way.
Example which encrypts and decrypts a string using a randomly generated 32 character password. In real-life you would add your own 32 character password instead.
import AES256CBC let str = "My little secret" let password = AES256CBC.generatePassword() // returns random 32 char string // get AES-256 CBC encrypted string let encrypted = AES256CBC.encryptString(str, password: password) // decrypt AES-256 CBC encrypted string let decrypted = AES256CBC.decryptString(encrypted!, password: password)
Run on Ubuntu with Docker
We ❤️ server-side Swift 3, 4 & 5 AES256CBC works under Linux. For Docker you can use the included Dockerfile or simple run
test_in_docker.sh which will create a self-removing docker container and runs test in them.
Why do I get nil as result?
If anything goes wrong, most likely due to a password which is not 32 characters long, then
decryptString() return nil.
What about the initial vector?
You don’t need to worry about the important initial vector which is required to make AES-256 much more secure. AES256CBC automatically generates a random initial vector for you and adds it to the start of the encrypted string. During decryption AES256CBC reads the first 16 characters of the encrypted string and uses them as initial vector to decrypt the remaining encrypted string.
Where is it used?
Contact & Contribute
If you have questions please contact Sebastian via the dedicated SwiftyBeaver Twitter account. Feature requests or bugs are better reported and discussed as Github Issue.
Please contribute back any great stuff, especially bugfixes & security issues! Each new bugfix, feature request or addition/change should be put in a dedicated pull request to simplify discussion and merging.
Thanks for testing, sharing, staring & contributing!
AES256CBC is released under the MIT License. The core crypto logic is a tailored version of CryptoSwift written by Marcin Krzyżanowski, please read & respect his license which can be found in the middle of the file AES256CBC.swift, too.
*Note that all licence references and agreements mentioned in the AES256CBC README section above are relevant to that project's source code only.