Privacy is very important today and we have a couple of options to encrypt our users’ data on iOS. We already have common crypto available on iOS but recently I came across a much simpler library that you can use. In this short article we’ll go over the basics of using CryptoSwift and get you started with it…
Install
There are many ways to install CryptoSwift. You can use embedded frameworks, Carthage, pods or even the swift package manager. By far, the easiest way to get started is by using cocoapods. So go ahead and add the library to your podfile and run pod install:
Hopefully, that was pretty uneventful for you π Now we can cover some basics of what the library can do for you…
Usage
CryptoSwift will have pretty much everything you’ll need. Some of the things that you’ll most definitely use are digests and, well, encryption π Using digests is incredibly simple because of the string, array and data extensions that you get for free. Check out this example of using some common digests:
Pretty simple, right π
In this next example we’re encrypting a string using a Rabbit stream cipher and converting it to base 64. It sounds more complicated than it really is:
Of course, decryption works in reverse, as you would expect π
One last example we’ll cover today is the famous AES cipher. Using it is pretty much the same as using the above cipher:
The encrypt function takes in a utf8 array so we have to convert the string to it. And that’s pretty much it for today π
Conclusion
This certainly wasn’t a long article. But the CryptoSwift library is so simple to use that it didn’t have to be π It’s a great replacement for common crypto and is so much easier to use. CryptoSwift is very popular on GitHub and is actively maintained, so you know it won’t disappear over night π
I just thought I’d share this great find with you this week and I hope it’ll help you out in your development. You can find the very short example on GitLab and you can always go and check out CryptoSwift on GitHub and they also have a website.
I told you it was going to be a short one today π As always…
Have a nice day π
~D;
I am using this, but i need the decryption code for my c# server.
Can i use custom Key ??