My iOS app sends and receives messages from main server. I want these messages to be encrypted. How do you encrypt-decrypt an AES-256 string on iOS6? Is there a "native" solution?
-
There are *lots* of answers explaining how to use AES encryption on iOS. Did you try Googling for "AES-256 iOS"? Are you having a specific issue? – Jesse Rusak May 01 '13 at 19:55
-
1NSURLConnections handle the ssl in https automatically, is that what you need? – Kevin May 01 '13 at 19:55
-
http://stackoverflow.com/a/2039973/162361 answers this question pretty well, and has some good links to code that looks solidly written. – zadr May 01 '13 at 19:57
3 Answers
OpenSSL is not bundled with iOS, but you can still compile it yourself and link it into your application. You can also use Common Crypto.
The reason OpenSSL is not bundled is because it is not possible to upgrade system versions of OpenSSL without breaking compatibility with applications that depend on older versions.
You should not "use AES-256" to encrypt your messages because AES-256 is just a cipher, it does NOT make your messages secure. You should use a higher level facility, like SSL or TLS. Think of it this way: AES-256 is like a brick. You want a house. Houses are secure, and you can build houses out of brick. Owning a brick does not make you secure. Using AES-256 does not make your protocol secure.

- 205,541
- 37
- 345
- 415
Yes iOS 6 supports OpenSSL.
Use this : Firstly add Security Framework in your project.
Then create Category using this Encryption/Decryption Category
Then Import :
#import <CommonCrypto/CommonCryptor.h>
#import "NSData+Encryption.h"
Use these :
- (NSData*) encryptString:(NSString*)plaintext withKey:(NSString*)key {
return [[plaintext dataUsingEncoding:NSUTF8StringEncoding] AES256EncryptWithKey:key];
}
- (NSString*) decryptData:(NSData*)ciphertext withKey:(NSString*)key {
return [[[NSString alloc] initWithData:[ciphertext AES256DecryptWithKey:key]
encoding:NSUTF8StringEncoding] autorelease];
}
Check out this link : ios-openssl
Hope it helps you.

- 1
- 1

- 9,893
- 3
- 40
- 61
I would recommend to use CCCrypt calls.
You can see examples in other threads:
AES Encryption for an NSString on the iPhone
iOS 5: Data encryption AES-256 EncryptWithKey: not found
In the other hand I think Dietrich option has more sense.

- 1
- 1