سؤال

In my project, I am encrypting some data (string) using the 3DES encryption algorithm. The string I pass to the encryption function returns me a NSData object.

Now I want to convert NSData to NSString, so that I can send that string to server.

So I used this code to convert NSData to NSString

NSString *stringCreated = [[NSString alloc] initWithData:encryptedData encoding:NSASCIIStringEncoding];

But when I print this string, It prints very few characters on the console. I think there are few characters which is making a sequence of "\0" due to which it prints the string upto that character only.

I tried to encode the data with NSUTF8StringEncoding but it returns me (null).

I want to send the complete string to the server, what to do now?

هل كانت مفيدة؟

المحلول

This will not work since encrypted string is binary data. Convert it to Base64, if you need to use textual representation.

Here is described convertion of NSData to NSString : Converting NSData to base64

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top