Cocos2d-x tutorial (25)-Local Data Encryption

Source: Internet
Author: User

 

When we use local data to store CCUserDefault, there will be a defect, that is, the storage method used by CCUserDefault is plain text storage, which is very convenient for gamers to modify the archived data. What we want to learn today is how to use the SHA1 message digest algorithm to encrypt the data stored in CCUserDefault.

SHA1 library files: http://www.tamale.net/enter the web page, find the SHA-1 click to download, decompress the two files sha1.h and sha1.cpp copy to the project directory.

The encryption process using the information digest algorithm is as follows:

1. First, use CCUserDefault to store a data

2. Use the addBytes method of sha1 to write the data to be verified.

3. create one more key. The key still needs to be written, but it will be hidden in the encoding. When we retrieve the stored data, we will also retrieve the key value and then compare the verification code, if they are the same, the data is not modified. Of course, if someone finds the key in your project compilation, it's another thing... but the average player doesn't have this strength.

See the code below:

First, introduce the header file:

 

# Include sha1.h

Then I added the following code in the init () method of HelloWorld:

Console output result:

If the verification result is the same, the data is not modified.

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.