objective c - How to convert NSData to NSString and revert the NSString to NSData? -


my task encrypt file(.png, .txt, any..)

in order achieve doing

encryption:

  1. read file , store nsdata.
  2. convert nsdata nsstring.
  3. encrypt nsstring of aescrypt
  4. store nsstring in file

decryption

  1. read encrypted string
  2. decrypt of aescrypt
  3. convert nsdata
  4. save location

below code doing in order convert file nsstring:

nsstring* sourcefile = @"/users/vikas/desktop/thehulk.png";  nsdata *data = [[nsfilemanager defaultmanager] contentsatpat h:sourcefile];  nsstring *dataasstring = [[nsstring alloc] initwithdata:data encoding:nsutf8stringencoding]; 

problem:

the above code able read , store file nsdata when converting nsdata nsstring, value getting nil

research

stackover flow 1

stackover flow 2

s.p: if have better suggestion file encryption please let me know newbie.

according this blog string data conversion forces trailing \0 byte, might have remove. can done follows:

data = [data subdatawithrange:nsmakerange(0, [data length] - 1)];

try see if works you.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -