Ios-plist file des encryption

Source: Internet
Author: User

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.

12345678910111213141516171819202122232425262728 //生产加密题库- (NSArray*)makeQuestionData;{    NSString*filePath = [[NSBundlemainBundle] pathForResource:@"team"                                                         ofType:nil];    if(filePath)    {        NSString *str = [NSStringstringWithContentsOfURL:[NSURLfileURLWithPath: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"]);                             }        }    }    returnnil;}

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.