My task is to encrypt a file(.png, .txt, any..)
In order to achieve it what I doing is
Encryption:
- Read a file and store it into NSData.
- Convert NSData to NSString.
- Encrypt the NSString with help of AESCrypt
- Store the NSString in a file
Decryption
- Read the encrypted string
- Decrypt it with the help of AESCrypt
- Convert it back to NSData
- Save it back to some location
Below is the code that I am doing in order convert a file to 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 is able to read and store the file to NSData however when I am converting the NSData to NSString, the value I am getting is nil
Research
S.P: If you have better suggestion for file encryption then please let me know as I am newbie.