我从服务器获得了NSString
变量的响应,我需要使用此值NSString
来解密3DES,但必须是NSData
。我尝试了从NSString
到NSData
的转换,但由于它更改了值的内容,因此无法正常工作。这是我的代码:
outputStream write:[encrypted bytes] maxLength:[encrypted length]];
uint8_t buffer[1024];
int len = [inputStream read:buffer maxLength:sizeof(buffer)];
myString = [[NSString alloc] initWithBytes:buffer length:len encoding:NSASCIIStringEncoding];
/* Here I get the response from server as NSString, and this exact value must be decrypted */
NSLog(@"response of the server in nsstring %@", mystring);
NSData *responseserv= [mystring dataUsingEncoding:NSUTF8StringEncoding];
/* I convert it to NSData but the content of the value has changed*/
NSLog(@" response of the server in nsdata: %@", responseserv);
NSString *decrypted = [[self class] tripleDesDecryptData:responseserv key:@"Xm9d7@4Ru&2YaP&?14niO$f%" error:nil];
答案 0 :(得分:0)
尝试这样做..
NSString* str = @"teststring";
NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];
这是将NSString转换为NSData的方法