iOS Security: How to work with AES256 encrypt mechanism

Maksim Vialykh
2 min readJun 21, 2018

--

Hello, dear reader.

Today we try to encrypt and decrypt data for iOS using swift language and support tools.

What we need is to encrypt our data using AES encrypt standard.
It is using to store secured data into iOS application.
Main task is to use swift and iOS frameworks as possible.

Wikipedian AES illustration

Let’s start!

Some theory before practise.

What is AES?

It is Advanced Encryption Standard, symetric block encrypt mechanism. 256 in AES256 is a key size in bits.

In iOS we can use CommonCrypto library to encrypt/decrypt data.
You can read more about CommonCrypto and Cryptographic Interfaces here https://developer.apple.com/security/.

So, CommonCrypto was written some years ago in Objective-C.

Let’s have a look how to work with CommonCrypto using swift.

Let’s implement CommonCrypto using swift

  • Add framework into project
Import CommonCrypto
  • A simple Crypter Struct which works with CommonCrypto under the hood
Crypter Struct
  • Use crypter where it’s needed
Crypter usage

Yep! You’ve done it!

Remember, the receipt to success is continuous learning and communication with colleagues including, self-education.

This was a small guide about Data Security in iOS and small Crypter for AES256 based on Apple CommonCrypto framework. Read more on Apple Developer site. Don’t stop self-education. If you decide to work with Data Crypter, please use CommonCrypto Apple framework, not opensource alternatives, because CommonCrypto has a strong security level.

Subscribe to my account to get notifications about new stories.

If you still have questions — write about it in the comments. I’ll answer them in future articles.

--

--