Rajan Balana
Rajan Balana

Reputation: 3815

Want to convert 3DES Encrypted NSData to NSString

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?

Upvotes: 1

Views: 677

Answers (1)

Nickolay Olshevsky
Nickolay Olshevsky

Reputation: 14160

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

Upvotes: 3

Related Questions