0

I have a WCF service, currently expecting byte[] as input parameter, but I want to send NSData from iOS. These types seem incompatible.

I've read a lot about this and most suggest that I convert the NSData to a base64 string.

Will this work for obscured data? I.e. my NSData consists of NSData that was passed through an AES256 Encryption algorithm. I don't think this data can be converted back to string successfully.

Matthys Du Toit
  • 2,168
  • 3
  • 21
  • 34
  • Some code of what you've tried would be good, but you can get the raw bytes from NSData. See this: http://stackoverflow.com/questions/724086/how-to-convert-nsdata-to-byte-array-in-iphone – Tom Irving Mar 18 '13 at 18:45

1 Answers1

0

Thank you Tom

I think sending the raw bytes would most probably have worked, but in the end I opted to convert the NSData to a base64 NSString and send that instead.

Works great!

PS> Could someone please give me some rep? I'd like to participate more, but no one is voting on anything I post.

Here is my profile with my 2 or 3 other questions: https://stackoverflow.com/users/1014983/matthys-du-toit

Community
  • 1
  • 1
Matthys Du Toit
  • 2,168
  • 3
  • 21
  • 34
  • Converting to Base64 works but greatly increases the amount of data sent over the wire. I would use that only as a last resort. It's simply sloppy coding. – Oliver Weichhold Mar 20 '13 at 12:40
  • Hi Oliver, I was unaware of that, thank you for the heads up. Would you recommend I use Tom's linked solution and send raw bytes instead? I'm experiencing random data corruption with the base64 string method anyway. – Matthys Du Toit Mar 20 '13 at 19:38
  • Yes, Byte Array or Stream. – Oliver Weichhold Mar 21 '13 at 09:11
  • The byte array data is somehow corrupted, see my related question here: http://stackoverflow.com/questions/15536429/data-corrupt-after-converting-byte-to-nsdata . I'll give stream a go next. – Matthys Du Toit Mar 21 '13 at 11:03
  • I'm afraid I can't help you with your related question since I generally do my iOS Development in C# using Monotouch. – Oliver Weichhold Mar 21 '13 at 13:02
  • Hi Oliver, I ran a test on my app, comparing byte[] vs a base64String. What you said about a base64String being over-sized made sense to me, but when I tested this theory, the byte[] for the same data was almost double the size of the base64String when sent over the wire. – Matthys Du Toit Mar 25 '13 at 11:25
  • Base64 encoding turns 3 bytes into 4 in the conversion. So you see this is impossible. Unless you are not dealing with the same byte sequence in both cases - which I suspect in your case. – Oliver Weichhold Mar 25 '13 at 14:57