how can I translate a NSString to NSData? And the data has the same content as the string
Posted
by someonemaybe
on Stack Overflow
See other posts from Stack Overflow
or by someonemaybe
Published on 2010-03-11T09:00:33Z
Indexed on
2010/03/12
8:17 UTC
Read the original article
Hit count: 461
NSString * theString=@"e88d";
NSData * data;
// something I should implement
NSLog(@"%@", theString);
NSLog(@"%@",[data description]);
I want the results of the two printings are the same.
AES encryption and decryption:
(1).The server:
if the plaintext is :@"abcd";
the AES encrypted data(NSData data type) is :"d882830c dc892036 4345839f 13c7516a";
(2).in my local app, my code is :
NSData*data=[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://..."]]; NSString * mystring= [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
However, to decrypt data successfully, I must got a data(NSData date type) which equals to "d882830c dc892036 4345839f 13c7516a".But it is the mystring (NSString data type) not the data(NSData data type) that equals to the right value.
the encryption and decryption function both need a data(NSData data type) as input datas.
- (NSData*)AES128EncryptWithKey:(NSString*)key;
- (NSData*)AES128DecryptWithKey:(NSString*)key;
© Stack Overflow or respective owner