NSString is NULL [closed]
hiiii freinds please any guys say me why str is NULL i will be creasy
NSString *strData = @"issam bey" ;
NSMutableData *objNSData = [NSMutableData dataWithData:[strData dataUsingEncoding:NSISOLatin1StringEncoding]];
objNSData = [objNSData EncryptAES:@"12345678901234561234567890123456"];
//NSString* decryptedStr = [[NSString alloc] initWithData:objNSData encoding:NSASCIIStringEncoding];
NSString *str=[[NSString alloc] initWithData: ob开发者_运维技巧jNSData encoding:NSUTF8StringEncoding];
NSLog(@"%@",str);
If you are doing encryption and decryption then read Encrypting / Decrypting / Base64 Encode / Decode in iPhone Objective-C.
For AES256 encryption-decryption, read Adding methods to NSData and NSString using categories to provide AES256 encryption on iOS.
NSString's initWithData:encoding:
will try to use the specified data to create a string using the encoding you tell it to use. If it can't do that then it will return nil
.
The fact that you tried a different encoding and got a value instead of nil
should tell you what's wrong - your encoded data can't be represented by a UTF-8 string but can be represented by a Latin-1 string.
Just out of interest, why do you want to encrypt the data and then view it as a string again?
精彩评论