objective-c how to remove encryption from this code

Discussion in 'iOS Programming' started by jsherk, Jan 9, 2012.

  1. jsherk macrumors newbie

    Jan 9, 2012

    I am very new to objective-c and am finding it to be a very difficult to fully grasp how it works.

    Anyways, the code below retrieves an encrypted xml plist file from my server and then decrypts for use in my iPhone app. But I just discovered that encryption is whole big issue that I really don't want to deal with right now, so I need to remove the encryption part (I have no problem doing that on server side).

    So currently it's this:
    SERVER SIDE: XML Plist file > Encrypt > Base64encode
    IPHONE SIDE: request and receive file > base64decode > decrypt > XML Plist file.

    I need to remove the decrypt part, so it's like this:
    SERVER SIDE: XML Plist file > Base64encode
    IPHONE SIDE: request and receive file > base64decode > XML Plist file.

    I have played with this code but can't get it right. Any help appreciated. I am sure it's something to do with SecKeyWrapper, but not able to remove it.


        NSURL *url = [NSURL URLWithString:@"http://www.mydomain.com/plist-settings.php"]; //Retrieve file
        NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:5.0];    
        [NSURLConnection connectionWithRequest:request delegate:self];
        sync_data = [[NSMutableData alloc] init];
    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)_data{
        [sync_data appendData:_data];
    - (void)connectionDidFinishLoading:(NSURLConnection *)connection{
        char * key = "(mASFi14%12As./*";
        NSData * symmetricKey = [NSData dataWithBytes:key length:16];
        CCOptions pad = kCCOptionECBMode;
        NSMutableData *theData = [[NSData dataFromBase64String:[[NSString alloc] initWithData:sync_data encoding:NSUTF8StringEncoding]] mutableCopy];
        if ([theData length] == 0) {
            [theData release];
        sync_data = [[[SecKeyWrapper sharedWrapper] doCipher:theData key:symmetricKey context:kCCDecrypt padding:&pad] mutableCopy];
        [theData release];
        NSDictionary *dictServer = nil;
        CFPropertyListRef plist = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,(CFDataRef)sync_data, kCFPropertyListImmutable, NULL);
  2. ianray macrumors 6502

    Jun 22, 2010
    I would suggest mapping each of those steps to the code, in order to make things clearer:

        sync_data  -->  base64decode --> theData
        theData    -->  decrypt      -->  sync_data
        sync_data  -->  XML Plist    -->  plist
    Now all you have to do is remove the relevant step... Good luck :)

Share This Page