New to iOS dev, trying to work on encoding data for secure data storage in db.
I found the current example here: https://github.com/RNCryptor/RNCryptor-objc
This is my code.
NSString * aPassword =@"tempkey";
NSData *data = [@"Data" dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSData *encryptedData = [RNEncryptor encryptData:data
withSettings:kRNCryptorAES256Settings
password:aPassword
error:&error];
NSLog(@"Data: %@", [[NSString alloc] initWithData:encryptedData encoding:NSUTF8StringEncoding]);
My log
2016-10-20 11:41:52.662 BlueBoard[57245:10027277] Data: (null)
Am I missing a step in this process? I've confirmed that it's null because it the db its being stored as null as well.
Your issue isn't that
encryptedDataisnil, it's that you are attempted to create anNSStringfrom data that doesn't represent a string.If you wish to convert
encryptedDatainto a string for storage or other purposes, you should convert the data into a Base 64 encoded representation. Do this with thebase64EncodedStringWithOptions:method.Of course when you want to decrypt the string later, you will need to convert the Base 64 encoded string back into
NSData, and then decrypt that data.