Search code examples
iosobjective-cxcodebase64nsdata

How to separate 16 bytes from Base 64 string in iOS using objective c?


Hello I am appending two NSDatas to form a NSMutableData using objective c . The code is given below:

NSData *data1 = key1;
    NSData *data2 = encryptedData;
    NSMutableData *completeData = [data1 mutableCopy];
    [completeData appendData:data2];
    NSLog(@"Mutable data%@", completeData);
    NSLog(@"Nutable data IV: %@", [completeData base64EncodedStringWithOptions:0]);

At last I am getting a Base64 string in the form of "9G1WmT41boXfxqJeBhfngb1oq3TB7IcrQEzKqSre6vdp2fzvggv/6+MMxXL4viB3kHJmqxynsPknp4pzMx9MHIMls2lr7VGc2cWPjTG9fW+aq26cxTzkdg7lc+UPRY0b"

Is it able to separate the first 16 bytes of NSData or Base64String? Because I want to separate first 16 bytes and pass the rest .

Please tell how to do that ?


Solution

  • You could use subdataWithRange: to remove the 16 first bytes :

    NSData * truncatedData = [completeData subdataWithRange:NSMakeRange(16, completeData.length-16)];