Cocos2d-x encryption MD5/sha1/base64

Source: Internet
Author: User

I. There are three common encryption scenarios:

1. Resource encryption, video and music (Anti-Piracy)

2. Encryption during network transmission to prevent interception and data modification (Anti-cheating)

3. Game Data Encryption (Anti-cheating)

Ii. encryption: prevents piracy and cheating.

Iii. Common encryption methods:

MD5

The full name of MD5 is message-Digest algorithm 5 (Information-AbstractAlgorithmDeveloped by MIT laboratory for computer science and RSA Data Security Inc Ronald L. Rivest in Early 1990s, developed by md2, md3, and md4. The function of this function is to compress large-capacity information into a confidential format (that is, to convert a byte string of any length into a long SIZE) before signing a private key with the digital signature software. integer ). Whether md2, md4, or MD5, they all need to obtain a random length information and generate a 128-bit information digest.

In computing, it is unlikely to find two different inputs with the same hash value. That is to say, the hash values of the two groups of data match only when the corresponding data matches. A small amount of data changes will generate unpredictable large numbers of changes in the hash value. Therefore, it is difficult for you to find clues from the encrypted text.
 

Common MD5 encryption is a solution with only encryption and no decryption method, that is, irreversible. MD5 encryption generates a string of characters. The MD5 API is simple.

MD5 is improved by md4, md3, and md2, which mainly enhances the complexity and irreversible nature of algorithms.

MD5 has been widely used in computer security. However, in recent years, MD5 vulnerabilities have been constantly discovered and the computing capability of today's computers has been constantly improved. Now, it is possible to manually construct two information with the same MD5 checksum value.[2], making this algorithm no longer suitable for today's security fields. Currently, MD5 algorithms are widely used in error checking of common data due to their common, stable, and fast features. For example, in some BitTorrent downloads, the software checks the integrity of the downloaded file fragments by calculating MD5.

The MD5 algorithm is old and the hash length is fixed to 128 bits. As the computing capability of the computer increases, it is possible to quickly find a "Collision. Therefore, MD5 should not be used in scenarios with high security requirements.

Base64:

Encryption/Decryption

Sha1:

One-way encryption, non-reverse. MD5 and sha1 are currently the most widely used algorithms. Both algorithms are based on md4, but slightly different. Generally, the sha1 computing speed is relatively slow, but the performance of anti-poverty is better. It is also used to compare file integrity in P2P software.

There are other open-source encryption libraries, but they generally do not use such advanced libraries. Therefore, these encryption methods are enough. If you are interested, you can study other libraries on your own.

Note: Introduce the header file in the C style. Note the path of the header file. If the storage path is different, instead of the crypto folder, you must change the header file path.

# Include "crypto/cccrypto. H"

Extern "C "{
# Include "crypto/base64/libb64.h"
# Include "crypto/MD5/md5.h"
# Include "crypto/sha1/sha1.h"
}

Source code of three data encryption methods encapsulated by cocos2d-x

Http://download.csdn.net/detail/xzongyuan/5640973

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.