Domanda

I want to create my app with encryption for some properties, that I will save in CoreData So I want use AES256. What the best solution for key ? So I can use some identifier from device, but I want use iCloud, so what individual constant I can use for each user? I don't want to hardcode key. But I don't know what identifier (like UUID in iPhone), that will be always constant and similar for one user in iCloud.

È stato utile?

Soluzione

There is no unique constant identifier for an iDevice that you can use anymore. However, you can just make a new UUID once your app is started for the first time, store this in the NSUserDefaults and use that UUID - it will never change as long as the app is not installed anew (updates will still keep the UUID intact).

Create a UUID like this when your app starts for the first time:

NSString* knownUUID = [[NSUserDefaults standardUserDefaults] objectForKey:@"myUUID"];
if (!knownUUID)
{
    NSString *uuid = [[NSUUID UUID] UUIDString];
    [NSUserDefaults standardUserDefaults] setObject:uuid forKey:@"myUUID"];
    [NSUserDefaults standardUserDefaults] synchronize]; // store defaults
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top