The New Cocos2d-X Encryption Solution

The New Cocos2d-X Encryption Solution

Features :

  1. Support all types of file encryption. For Cocos2d-X, except for .ttf;.mp3;.ogg, which requires Streaming mode (generally audio playback and font resolution memory usage, performance requirements), all other file types can be encrypted.
  2. Security, refuse to use the string fool to store the key, improve the difficulty of cracking (don’t ask me if this solution can be cracked, the Internet is not absolutely safe, to the hacker compiling the HOOK system API level, cracking is only a matter of time)
  3. By default, data is compressed with zlib, then encrypted with AES-CBC. Finally , the size of the APK or iPA package is basically the same as that of no encryption. If the compression is not performed first, the file data redundancy information is greatly reduced after encryption, and the size of file data does not decrease after compression. The final package will be very large than non-encryption, whether it is an APK or iPA is a zip algorithm compression format.
  4. High-performance decryption, AES-CBC decryption in memory is to reuse the original memory, and the decompression process will get the original data size from the signature, effectively avoiding frequent memory alloc/free or memory waste during decompression.

Use steps :

  1. Download x-studio365 10.0.3300.1001 at And install

  2. Next, you can use the command line to encrypt resources.
    x-studio365 -c -enc -cfg=D:\encrypt-cfg.xml -i=D:\OriginalRes1 -o=D:\EncryptedRes1
    Parameter description :
    -cfg=[file] : Specify the encryption configuration file for the encryption tool to save the encryption key and other encryption options
    -i=[path]: Specify the encrypted input directory
    -o=[path]: Specify the encrypted output directory
    Other parameter description :
    -j2 : Enable dual-threaded cryptographic resources
    -ft=*.png;*.csb : Specify the resource encryption file type
    -dc=.ttf;.mp3;.ogg : Specifies file types for copy directly, some types of files may not need to be encrypted
    (1) For the first encryption, the encryption tool will automatically generate the ivec and key required by the AES-CBC encryption mode , and the encryption config will be stored in the encrypt-cfg.xml file for set the key in the decryption runtime. the key/ivce is stored as C++ bytes array format.
    (2) If the encryption configuration file specified by the -cfg option already exists , the tool reads the encryption option from it , but if the same option is specified in both the configuration file and the command line parameters, the command line parameters override the encryption configuration file. the configuration file will be updated.
    (3) If you specify encrypt-cfg.xml already exist and need to change the key, then you only need to delete ivec and key elements from the encrypt-cfg.xml.

  3. Cocos2d-X Demo : , Based on the latest Cocos2d-X-3.17.1, and the decryption runtime also have test on Cocos2d-X-3.10, but you need change FileUtilsWin32's constructor access permission from private to protected or public

  4. For lua porject, at win32 please move encryption key/ivec setup code to SimulatorWin::run() such as:



Yea, and get a lot of problems and complicated review and also rejects during Apple review. No thanks.

@halx99 I sent a link to this around the office. Thanks for contributing to the community.

I’m glad to hear about. tks.

Update 2019.1.20, please pull EncryptManager.cpp from , fix some compile and compatible issues for Cocos2d-x older versions. And for apple platform, you need to rename EncryptManager.cpp to to compile.

i wish i could know this msg earlier beacause i have work a week for encryt resource in cocos2dx project

and now i still hava some problem about how to encrypt audio resource.

could you mind tell me where the cocos2dx read the audio source. i hava work a few hours to find it.

You can use out GitHub repo to look at the source code for the engine:

I suggest you don’t encrypt audio files, otherwise, the streaming play will doesn’t works well.

ok I will consider it, thank you for your suggestion

thanks, i will check it

Hi, can this solution be used on Cocos Creator too?

Maybe works with jsb.

Cool! Is it possible to support Mac?

it’s not working with cocos2d-x javascript 3.17.2
here error

Do you compile EncryptManager.cpp with your project?