I want to create random AES Encryption key (128 bit) in ios. I have searched in SO but I cannot find a good answer. Please give me some advice. thanks in advance.
UP
This might help
- (NSString *)getRandomKey{
NSString *alphabet = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY0123456789/=+";
NSMutableString *s = [NSMutableString stringWithCapacity:20];
for (NSUInteger i = 0; i < 20; i++) {
u_int32_t r = arc4random() % [alphabet length];
unichar c = [alphabet characterAtIndex:r];
[s appendFormat:@"%C", c];
}
NSLog(@"%@", s);
NSString *key = s;
return key;
}