How can I translate a NSString to NSData? And the data has the same content as the string?

I think this might answer your question Similar Stack Overflow Question.

Well,the printed out data is not the same as the string. – user230965 Mar 11 '10 at 9:16 probably because %@ you use in NSLog(@"%@",data); expects an NSString object, you're passing an NSData object. – Griffo 5 Mar at 9:26 if I use NSLog(@"%@",data description), I hope gdb will show: e88d.

How can I get the data? – user230965 Mar 11 '10 at 9:42 AES encryption and decryption: server: if the plaintext is :@"abcd"; the AES encrypted data(NSData data type) is :"d882830c dc892036 4345839f 13c7516a" 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 the AES encrypted string, 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.

– user230965 Mar 12 '10 at 8:03.

The description you wanna set is not an instance specific value. It's the description of the class/object. NSData will have a description of like: 'this is a data object'.

You can override this value thou by overriding the method. - (NSString *)description { return @"e88d"; //normally used for class description } Ofcourse you will have to inherit the NSData object for that and then override the description like code above. PS.

I don't think you wanna use description for this just explaining what the use of it is in every class. What you might want is: NSString * theString=@"e88d"; NSData * data=theString dataUsingEncoding:NSUTF8StringEncoding; NSLog(@"%@", theString); NSLog(@"%@",NSString alloc initWithData:data encoding:NSUTF8StringEncoding).

Interface NSString (Joke) - (NSString *)description; @end @implementation NSString (Joke) - (NSString *)description { return @"Panda! "; } @end @interface NSData (Joke) - (NSString *)description; @end @implementation NSData (Joke) - (NSString *)description { return @"Panda! "; } @end.

1 Overly complicated, a simpler more generic solution: #define NSLog(...) NSLog(@"Panda! ") – cobbal Mar 12 '10 at 9:40.

How about this NSData *data = NSData dataWithContentsOfURL:NSURL URLWithString:@"..."; NSData *decryptedData = data AES128DecryptWithKey:key; NSString *mystring = NSString alloc initWithData:decryptedData encoding:NSUTF8StringEncoding.

NSData will have a description of like: 'this is a data object'. You can override this value thou by overriding the method. Ofcourse you will have to inherit the NSData object for that and then override the description like code above.

I don't think you wanna use description for this just explaining what the use of it is in every class.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions