Question

I am developing an application including sqlite database. I want to encrypt and decrypt data's inside the database using AES encryption. I have successfully implemented the AES encryption and inserted the encrypted data's in the database. And am fetching the data's into a NSString.

Then how can I assign that string without changing the string value into a NSMutableData. Because I want to pass that data to AES decrypt method.

Was it helpful?

Solution

Here is some example of NSString <-> NSData conversion:

NSString *someString = @"string";

//NSString to NSData
NSData* data=[someString dataUsingEncoding: [NSString defaultCStringEncoding]];

//NSData to NSString
someString = [[NSString alloc] initWithData:data encoding:[NSString defaultCStringEncoding]];

NSLog(@"%@", someString);

OTHER TIPS

NSString *someString= @"This string will be converted to mutableData in the next line";

NSMutableData *someData = [[someString dataUsingEncoding:NSUTF8StringEncoding] mutableCopy];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top