CryptoSwift 0.1.0

Finally major update to CryptoSwift framework.

Crypto related functions and helpers for Swift implemented in Swift.

I really enjoy working on CryptoSwift in my spare time, this is why today I'm glad to announce version 0.1 with a major changes to the public API and to the internal state of the framework.

What's new

Cipher enum is no longer here. I replaced it with internal protocol. This change makes API easier to use and to manage. Now there's no need to use enum for ciphers. Now I can add more convenience initialisers, like the initialiser for key parameters as String, array or NSData and so forth, for example:

let bytes: [UInt8] = [0,1,2,3,4,5,6,7,8,9]  
let encrypted: [UInt8] = try! AES(key: "secret0key000000", iv: "0123456789012345").encrypt(input)  

or encrypt NSData with convenient extension:

let encrypted: [UInt8] = try! NSData().encrypt(ChaCha20(key: key, iv: iv))  
let encryptedData = NSData(bytes: encrypted)  

or String:

let base64: String = try! "my secret string".encrypt(AES(key: "secret0key000000", iv: "0123456789012345"))  

as you can see, internally input/output structure is array of bytes: Array<UInt8> with helpers that allows work with other structures, like NSData or String.

If you upgrade from version 0.0.x -> 0.x, please check updated examples from README file for detail. The upgrade should be straightforward in my opinion. If you have any issue, simply let me know.

iOS, OSX, watchOS

Support for iOS, OSX, watchOS and (tvOS soon). Thanks to the recent changes, integration with these platforms is much easier.

Optional Foundation Framework dependency

Starting with this release, CryptoSwift code base is not dependant on Foundation Framework, though it is very well integrated with Foundation classes like NSData thanks to nicely separated extensions. Turn out such dependency can be dropped without any impact to the conveniency of usage. This is awesome! In case Swift will go Open Source and will be ported to Linux, CryptoSwift code base should be ready to use there out of the box.


I had some spare time, and did some work to improve performance, especially the AES encryption. As a result, I changed AES implementation to very performant Gladman AES algorithm. Previously used, naive algorithm (it was good start to get how AES is working at all, however it is not performant at all). The current one is the fastest algorithm I know, the only faster is hardware acceleration. However, how fast it can be is constrained by the Swift compiler. Thanks to this change and some improvements to the Swift code itself, I was able to speed the operation by more than 14 times, and this is really awesome. MD5 and SHA should be better as well, however it was not the main focus this time.

What's next

More fun. Stay tuned.