0

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 ?

User1075
  • 819
  • 15
  • 36

1 Answers1

1

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

NSData * truncatedData = [completeData subdataWithRange:NSMakeRange(16, completeData.length-16)];
dspr
  • 2,383
  • 2
  • 15
  • 19
  • Thanks a lot can you help me with this link? https://stackoverflow.com/questions/64679465/how-to-add-salt-to-aes-encryption-in-ios-and-decrypting-it-using-objective-c – User1075 Nov 04 '20 at 18:31
  • I executed the codes you posted there but I was not able to reproduce your case : @"My encryption string" is returned the same after encryption and decryption. Can you tell me what's the problem exactly ? Maybe I misunderstood... – dspr Nov 04 '20 at 20:03
  • The problem is in android an encrypted key was generated and I was not able to decrypt it with the same here in my code ... we are using the same secret key – User1075 Nov 04 '20 at 20:08
  • 1
    Sorry but I'm afraid I cannot help because I don't use android/java and it could be a problem in the bridge between the two languages. Good luck anyway ! – dspr Nov 04 '20 at 20:29