2010-03-12 63 views
0

嗨串進行解碼,問題的編碼和在iPhone的SDK

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]; 
    } 

和現在我想,我編碼的字符串進行解碼。

但我不知道如何做到這一點。任何人都可以用代碼告訴我如何得到它。

任何人的幫助將不勝感激。 謝謝, Monish。

+0

複製? http://stackoverflow.com/questions/392464/any-base64-library-on-iphone-sdk – 2010-03-12 12:41:19

+0

我用過的鏈接的引用,但我得到的輸出,當我解碼文本爲: <50000053 60005365 4053656b 6b656b68 656b6861 6b686172 3861723a 41723a42 723a4265 76426574 62657468 65746861 6c68616c 68616c61 616c616d> – monish 2010-03-12 14:11:34

+0

夥計們請給我一個快速解決方案。 – monish 2010-03-12 14:35:31

回答