Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is risky as you can run the Strings utility on just about any app (try it, it's kinda scary) and get the strings from the code. Generally I'd recommend packaging the secrets in the app, but leave them on a secure server elsewhere. If you must put it in the app, one thing you can do is obfuscate the strings so it's not obvious.</p> <pre><code>NSString *secret = kTwitterClientSecret; NSData *secretData = [secret dataUsingEncoding:NSUTF8StringEncoding]; NSString *key = @"Twitter"; [secretData obfuscateOrDeobfuscateWithKey:key]; NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSString *path = [NSString stringWithFormat:@"%@/%@-%@", documentsPath, key, @"output"]; [secretData writeToFile:path atomically:NO]; NSLog(@"Wrote obfuscated data to: %@", documentsPath); </code></pre> <p>Where obfuscateOrDeobfuscateWithKey is a category on NSData</p> <pre><code>// Inspiration from: http://iosdevelopertips.com/cocoa/obfuscation-encryption-of-string-nsstring.html - (void)obfuscateOrDeobfuscateWithKey:(NSString *)key { // Get pointer to data to obfuscate char *dataPtr = (char *) [self bytes]; // Get pointer to key data char *keyData = (char *) [[key dataUsingEncoding:NSUTF8StringEncoding] bytes]; // Points to each char in sequence in the key char *keyPtr = keyData; int keyIndex = 0; // For each character in data, xor with current value in key for (int x = 0; x &lt; [self length]; x++) { // Replace current character in data with current character xor'd with current key value. // Bump each pointer to the next character. *dataPtr = *dataPtr ^ *keyPtr; dataPtr++; keyPtr++; // If at end of key data, reset count and set key pointer back to start of key value if (++keyIndex == [key length]) { keyIndex = 0, keyPtr = keyData; } } } </code></pre> <p>Then you can declare a constant to be something like </p> <pre><code>static unsigned char const kTwitterClientSecret[] = { 0x00, 0x00, 0x00, ... etc ... }; static unsigned int const kTwitterClientSecret_len = LENGTH; </code></pre> <p>Then to get the string back you can do </p> <pre><code>[NSString deobfuscatedStringWithBytes:kTwitterClientSecret length:kTwitterClientSecret_len key:@"Twitter"]; </code></pre> <p>Where this is a category on NSString</p> <pre><code>+ (NSString *)deobfuscatedStringWithBytes:(const void *)bytes length:(NSUInteger)length key:(NSString *)key { NSData *deobfuscatedData = [NSData dataWithBytes:bytes length:length]; [deobfuscatedData obfuscateOrDeobfuscateWithKey:key]; return [[NSString alloc] initWithData:deobfuscatedData encoding:NSUTF8StringEncoding]; } </code></pre> <p>This will do very simple obfuscation and will not show up in strings. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload