Search code examples
objective-cnsstringaesnsdata

NSData to NSString and vise versa


My user is prompted to enter in RAW NSData (like: <0201581d 9fc84f7b bf136a80 e7fc9572>)

This raw data is an AES encrypted NSString.

However, the issue is converting those actual bytes of data <0201581d 9fc84f7b bf136a80 e7fc9572> into an NSData type itself.

  1. Prompted to enter data
  2. Enters data --> @"<0201581d 9fc84f7b bf136a80 e7fc9572>"
  3. Needs to make entered data into an NSData type rather than the NSString which was passed.

In short; How do I make this: <0201581d 9fc84f7b bf136a80 e7fc9572> into the NSData's data? Making an integer hold the data HALF works (because the type is too short) so It needs to be an NSString.


Solution

  • This is extremely similar to NSString (hex) to bytes. The answer there will work for you if you remove the excess punctuation.