0

HI Guys,

   Here I am having a problem In encoding/decoding the strings.

Actually I had a string which I am encoding it using the base64.which was working fine.
And now I need to decode the string that was encoded before and want to print it.
I code I written as:

I imported the base64.h and base64.m files into my application which contains the methods as:

+ (NSData *) dataWithBase64EncodedString:(NSString *) string;
- (id) initWithBase64EncodedString:(NSString *) string;
- (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength;

And the code in my view controller where I encode the String is:

- (id)init {
if (self = [super init]) {
    // Custom initialization

  userName = @"Sekhar";
  password = @"Bethalam";
    }
    return self;
    }

-(void)reloadView
{
 NSString *authStr = [NSString stringWithFormat:@"%@:%@",userName,password];
 NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding];
 NSString *authValue = [NSString stringWithFormat:@"%@", [authData base64EncodingWithLineLength:30]];
 NSLog(authValue);
 //const char *str = authValue;
 //NSString *decStr = [StringEncryption DecryptString:authValue];
 //NSLog(decStr);

 //NSData *decodeData = [NSData decode:authValue];
 //NSString *decStr = [NSString stringWithFormat:@"%@",decodeData];
 //NSStr
 //NSLog(decStr);
}

   -(void)viewWillAppear:(BOOL)animated
   {
     [self reloadView];
    }

and now I want to decode the String that I encoded.

But I dont know How to do that.can anyone suggest me with code how to get it.

Anyone's help will be much appreciated. Thank you, Monish.

monish
  • 1,355
  • 5
  • 18
  • 32
  • duplicate? http://stackoverflow.com/questions/392464/any-base64-library-on-iphone-sdk – David Gelhar Mar 12 '10 at 12:41
  • I used the reference of the link u had posted but Im getting the output when I decode the text as: <50000053 60005365 4053656b 6b656b68 656b6861 6b686172 3861723a 41723a42 723a4265 76426574 62657468 65746861 6c68616c 68616c61 616c616d> – monish Mar 12 '10 at 14:11
  • Guys Please Give me a quick solution. – monish Mar 12 '10 at 14:35
  • Cross post: http://efreedom.com/Question/1-2432680/Problem-Encoding-Decoding-String-iPhone-Sdk – sixtyfootersdude Nov 13 '10 at 16:53

1 Answers1

0

You need to use the Base64DecodeLookup method in the Base64 class. For a solid description on how to use that for the mac and the iphone try checking out this article. http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html

Cheers

Mark Hazlett
  • 126
  • 1
  • 10