Reprint please indicate source: http://www.cnblogs.com/gexun/p/3705207.html, thank you.
These days have been doing a knowledge question and answer project, because the preliminary project topic is relatively small, so the title is written in the local plist file, directly read it.
The company PM worry about the problem leaked, so we have to give plist file encryption, this can put me disabled, because I have never done encryption, online search a lot of information, are simple string encryption, no special to plist file encryption, and then really no way, consulted the company of the great God, finally done. Specifically here to tell me the same way iOS rookie, hope to help you, if there is a better way for Daniel, want to point out and improve.
I use DES encryption, do not know the students can first look at these 2 articles:
Http://bbs.9ria.com/thread-242572-1-1.html
http://blog.csdn.net/kylinbl/article/details/8641246
Next, let's comb the entire plist file encryption process:
1. First import des related files in your project
2. Import the DES header file into the class you want to encrypt
3. Write an encrypted plist file method, and then Viewdidload method inside call it, here note plist file format to change under, Remove the plist file you want to encrypt. plist, the file you import is no longer in plist format, and is not opened in plist format, but in XML format. Otherwise, the compilation will not succeed.
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
//生产加密题库 - (
NSArray *)makeQuestionData; {
NSString *filePath = [[
NSBundle mainBundle] pathForResource:@
"team"
ofType:
nil
];
if (filePath)
{
NSString *str = [
NSString stringWithContentsOfURL:[
NSURL fileURLWithPath:filePath]
encoding:
NSUTF8StringEncoding
error:
NULL
];
if (str)
{
NSString *desStr = [DES encryptString:str];
if
(desStr)
{
[desStr writeToFile:[MHFileTool getLocalFilePath:@
"jiamiTeam"
]
atomically:
YES
encoding:
NSUTF8StringEncoding
error:
NULL
];
NSLog
(@
"---dest path:%@"
,[MHFileTool getLocalFilePath:@
"jiamiTeam"
]);
}
}
}
return nil
; }
|
4. The corresponding encrypted plist file for your old plist file will be generated locally in your project.
4.1 We're going to make a break on this side of the way, and then step by step down to my NSLog method side:
4.2 This time the console will print out the address of the locally generated encrypted file: (Here I used third-party write local file tool class Mhfiletool, directly lazy. )
4.3 This time we go to the program local sandbox directory to remove the encrypted plist file
5. Write a decrypted plist file on the original method of encrypting the Plist file, replace the encrypted plist file you just generated with the old one, so the encryption work is done!
6. Decrypt the file method. Call the decryption method directly, it is no longer one by one to repeat.
7. This article code demo:http://download.csdn.net/detail/gary5510/7287315