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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -