1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Asset - Scripts Fast & Secure File Encryption Scripts [Free] - Now supports opening encrypted .ini files

Discussion in 'Marketplace' started by acidemic, Oct 28, 2017.

  1. acidemic

    acidemic Member

    Joined:
    Jul 23, 2016
    Posts:
    115
    Fast Crypt Ultra - Encrypt / Decrypt & Compress your files, game resources and .ini files super fast and secure!

    [​IMG] [​IMG]

    [ Marketplace Link ]

    This is a set of scripts for secure and fast file encryption and encoding. This bundle contains many scripts that provide various features. Please read top section of each script carefully as it provides usage examples.

    GMS2 scripts:
    New scripts to work securely with encrypted .ini files:
    • ini_open_encrypted_zlib() and ini_close_encrypted_zlib() - Scripts to work with .ini files that provide Zlib compression.
    • ini_open_encrypted() and ini_close_encrypted() - Scripts to work with .ini files without compression. (GMS1.x compatible)
    File encryption scripts:
    • file_fast_crypt_ultra_zlib() - Secure zlib file compression & encryption using fast "Vulk@nos" algorithm with secret 1152 bit key. Use this for best security and smallest result file size! Zlib compressed files are up to 15 times smaller than the original input files. Best compression ratios are achievable for txt, ini, xml, json and other similar plain text files.
    • file_fast_crypt_ultra() - Secure file encryption using fast "Vulk@nos" algorithm with secret 1152 bit key. Very secure! (GMS1.x compatible)
    • file_fast_encode_ext() - Advanced file encoding by shifting each byte by variable number of bits. Use this if you want just to hide your game resources. No key is required, but user can decode your files if he knows how. (GMS1.x compatible)
    • file_fast_encode() - Very simple file encoding by shifting each byte by 128 bits. No key is required, but user can decode your files if he knows how. (GMS1.x compatible)
    Although scripts 'file_fast_encode_ext' and 'file_fast_encode' do not provide high security, they prevent players from looking into your game resource files such as level data, INI files, etc.. and changing their contents by obfuscating the original data.

    GMS1 scripts:
    • fast_file_key_crypt() - Secure file encryption using fast "Vulk@nos" algorithm with secret 1152 bit key. Very secure!
    • fast_file_encrypt() - Advanced file encoding by shifting each byte by variable number of bits. Use this if you want just to hide your game resources. No key is required, but user can decode your files if he knows how.
    • fast_file_crypt() - Very simple file encoding by shifting each byte by 128 bits. No key is required, but user can decode your files if he knows how.
    Although scripts 'fast_file_encrypt' and 'fast_file_crypt' do not provide high security, they prevent players from looking into your game resource files such as level data, INI files, etc.. and changing their contents by obfuscating the original data.

    Features:
    • (New) Scripts for decrypting encrypted .ini file from disk directly to the memory and encrypting .ini file from the computer's memory and saving already encrypted file to the disk. Unencrypted data will never be exposed. Two versions: with and without zlib compression.
    • (New) "FastCrypt Ultra" GUI tool that can help you with encrypting/decrypting various files. This tool uses two scripts file_fast_crypt_ultra_zlib() for encryption/decryption with compression and file_fast_crypt_ultra() for encryption/decryption without compression. So the files compressed by "FastCrypt Ultra" tool can be later decompressed in your game using these scripts.
    • Several scripts for fast & secure encryption.
    • Encryption using fast "Vulk@nos" algorithm with secret 1152 bit key.
    • Support for any file types (binary, text, images, ini, etc...).
    • Use of FAST 'buffers' instead of SLOW 'file_bin_' functions.
    • Can encrypt/decrypt to the same or to another new file.
    • Zlib compressed files are up to 15 times smaller than the original input files.
    • Encrypted/encoded file size using scripts without Zlib compression is exactly the same as the original file size.
    • Basic encoding scripts do NOT use base64 encoding (that's an advantage over other simple encoding scripts).
    • All scripts are heavily commented with detailed explanation of each step and usage examples at the top section of comments.
    • Supported by both GameMaker: Studio 1.x (except Zlib compression scripts) and 2.x (all scripts).
     
    Last edited: Sep 24, 2019
  2. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,496
    I'm not sure how fast is that "super fast", but you probably want to use "fast" type buffers instead of file_bin_ functions, as the later exist largely for compatibility purposes and are pretty slow as result.

    Also this is probably "encoding" rather than "encryption" if it doesn't even use a password.
     
    acidemic and zbox like this.
  3. acidemic

    acidemic Member

    Joined:
    Jul 23, 2016
    Posts:
    115
    Thank you for the comment. I will check the possibility to update this script with and change "file_bin_ functions" to "buffers".
     
  4. acidemic

    acidemic Member

    Joined:
    Jul 23, 2016
    Posts:
    115
    Script has been updated to use super fast 'buffers' instead of mega slow 'file_bin_' functions. Thanks to YellowAfterlife for this suggestion.
     
  5. acidemic

    acidemic Member

    Joined:
    Jul 23, 2016
    Posts:
    115
    Asset has been updated! Now you can securely encrypt your files with a secret key using new script 'fast_file_key_crypt(input_file, output_file, is_encrypted, encryption_key_string)' which uses fast "Vulkan" encryption algorithm created by me.
     
  6. zbox

    zbox Member GMC Elder

    Joined:
    Jun 21, 2016
    Posts:
    805
    PNelly likes this.
  7. acidemic

    acidemic Member

    Joined:
    Jul 23, 2016
    Posts:
    115
    The purpose of these encryption scripts is to hide external game resources from curious users, not from CIA, FBI, NSA, KGB, Stasi, etc. who would want to crack your game progress, savefiles or level data, etc by all means. "Vulcan" algorithm provides very fast encryption which can be used on mobile devices. Security is provided by encrypting data with pseudo-random generated sequence using MD5 & SHA1 based on the supplied secret key. The encryption sequence is changing all the time, so it produces non-repetitive encrypted end file. If you need much much stronger encryprion use AES, but it will be very slow. On my test platform Core i7-2600K it took "Vulcan" algorithm 4 seconds to encrypt 12mb file.
     
    Last edited: Nov 11, 2017
  8. zbox

    zbox Member GMC Elder

    Joined:
    Jun 21, 2016
    Posts:
    805
    Well that's fair enough if it is for pokey users... why isn't the first obscuring method you had good enough then!

    MD5 and SHA1 are hash functions, not encryption ones, just FYI.
     
  9. acidemic

    acidemic Member

    Joined:
    Jul 23, 2016
    Posts:
    115
    First method does not password protect files, it just hides them by mixing bits. New script encrypts files so even if someone get's access to the alhorhytm, he can't reveal the original contents of the file without a secret key. MD5 + SHA1 are used to generate long pseudo-random sequences based on the secret key for XOR encryption. I created these scripts as I could not find anything secure enough and fast for GMS to use in my game projects. Base64 encoding is way too simple for that and easily revealable, but AES scripts available on the market are far too slow. My scripts are in the middle of that. They give relatively good security and fast encryption/decryption speed. Also they are simple to understand and change for your project requirements if needed.
     
  10. Elevory

    Elevory Member

    Joined:
    Aug 27, 2016
    Posts:
    57
    Thank you, this is great. It's fast and appears to be reasonably secure. I modified the script so that unencrypted files are never written to the disk, instead passing them off to ini_open_from_string(). Working flawlessly so far.
     
  11. Colorics

    Colorics Member

    Joined:
    Apr 30, 2017
    Posts:
    8
    A massive thank you! This is exactly what I needed. Just encoding with base64 is not secure what so ever, but this is a great way to encrypt your variables for no naked eye to change.
     
  12. Zuljaras

    Zuljaras Member

    Joined:
    Jan 16, 2017
    Posts:
    414
    This is really nice!

    I just wonder does it work for all platforms? Like Xbox, PS4, Android etc?
     
  13. modivgames

    modivgames Member

    Joined:
    Aug 27, 2019
    Posts:
    4
    Hey,
    Could you share what you did with us?
    It's exactly what I'm trying to achieve. I Encrypted the game save files (.ini) before sending to Steam Cloud. But to load an encrypted .ini file using the ini functions is being a hell as the only way I found is to use:

    var cloudfile = steam_file_read("cloudfilename.ini");
    ini_open_from_string(cloudfile);

    So there's no place to use the encryption this way...maybe with your modification to the script I could be saved. :)
    Thanks in advance!
     
  14. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    318
    Though this doesn't answer your question, I could use some help as well. How do you encrypt/decrypt ini files with fast_file_key_crypt_compress()? I don't understand what the last argument is supposed to be.
     
  15. modivgames

    modivgames Member

    Joined:
    Aug 27, 2019
    Posts:
    4
    I'm using the gms 1.4 version of this asset and it doesn't support the compress feature, so I'm using the 'fast_file_key_crypt' script for encrypting/decrypting .ini files.
    This is how I'm using it:

    Code:
    //If the file doesn't exists create the file for the first time
    
    if !file_exists("newfile.ini")
    {
          //------------------------------------------
          //Start creating the .ini file for the first time
    
          ini_open("newfile.ini");
    
          //initialize the variables for the fist time if needed
          global.variable1 = ini_read_real("Settings","MUSIC",0);
    
          //Copy the actual content inside the .ini when saving
          ini_write_real("Settings","MUSIC",global.variable1);
    
          //Close the .ini file
          ini_close();
    
          //then encrypt for the first time.
          fast_file_key_crypt("newfile.ini","newfile.ini",true,"xyxyxyxy");
    }
          //------------------------------------------
    
    
    
    If the file already exists, before opening the .ini file you'll have to decrypt and after closing encrypt again:

    Code:
    //------------------------
    //Decrypt to Open
    fast_file_key_crypt("newfile.ini","newfile.ini",false,"xyxyxyxy");
    
    //Open the .ini file
    ini_open("newfile.ini");
    
    //...save or load thing from/to the ini file
    
    //Close the .ini file
    ini_close();
    
    //Encrypt again after closing the file
    fast_file_key_crypt("newfile.ini","newfile.ini",true,"xyxyxyxy");
    //------------------------
     
    OblivionSkull21 likes this.
  16. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    318
    So when I’m saving, I should call the encryption before opening the ini file, and when I’m loading, I should call the decryption before opening the ini file and then encrypt it again after closing it?

    What’s the last argument supposed to be? Just any thing? What’s the purpose of it?
     
  17. modivgames

    modivgames Member

    Joined:
    Aug 27, 2019
    Posts:
    4
    About the last Argument:
    It's a code(a combination of letters or numbers or both) that is used for creating unique encryption. Yes, can be any code but it's important to use aways the same code for opening and closing the same file.
    So you don't have to worry about it, just create a combination of about 8 letters and numbers to make your encryption unique.

    About how you should use the encryption for saving/loading:
    If the file has already been created and encrypted, 'always' before opening the .ini file you have to call the decryption script and after closing the .ini file you have to encrypt. But if you are creating the .inifile for the first time in the local computer folder you will not run the decryption when opening/creating for the first time, because technically there's nothing to decrypt yet, as the file has never been encrypted.

    Summing Up: Create the.ini file. Save the data you wanna save. Close the .ini file (this is the moment the ini file is been created). Encrypt the .ini file(for the first time). Now for the next time you call to open the .ini file, have in mind that the .ini file is now encrypted and before opening now you will have to decrypt. And after closing encrypt again...

    The script for encrypting and decrypting is the same, the only difference it's on the 3rd argument (True for Encrypting and False for Decrypting).
    So you call the script for decrypting. For example:

    fast_file_key_crypt("newfile.ini","newfile.ini",false,"xyxyxyxyx"); // decrypting

    Then after closing the .ini file you should encrypt:

    fast_file_key_crypt("newfile.ini","newfile.ini",true,"xyxyxyxyx"); // encrypting
     
  18. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    318
    Thank you so much! This helped a lot
     
  19. modivgames

    modivgames Member

    Joined:
    Aug 27, 2019
    Posts:
    4
    You're welcome! Glad to help.
     
  20. acidemic

    acidemic Member

    Joined:
    Jul 23, 2016
    Posts:
    115
    Elevory, great idea of using ini_open_from_string() for loading encrypted contents into the game, makes it totally safe now!

    I might update the asset with new scripts that would include this functionality.

    modivgames, perfect explanation!
     
    Last edited: Sep 16, 2019
  21. acidemic

    acidemic Member

    Joined:
    Jul 23, 2016
    Posts:
    115
    I have updated the asset in the Marketplace (GMS2 version only).

    Following new scripts were added:
    ini_open_encrypted_zlib() and ini_close_encrypted_zlib() - Scripts to work with .ini files that provide Zlib compression.
    ini_open_encrypted() and ini_close_encrypted() - Scripts to work with .ini files without compression.

    Following scripts were renamed for better naming consistency:

    (Note: Renamed scripts are fully compatible with their previous versions.)
    fast_file_key_crypt_compress() --> file_fast_crypt_ultra_zlib()
    fast_file_key_crypt() --> file_fast_crypt_ultra()
    fast_file_encrypt()
    --> file_fast_encode_ext()
    fast_file_crypt()
    --> file_fast_encode()

    Script file_fast_crypt_ultra_zlib() has been fixed. Previously decompressing a non compressed file would lead to crash.

    Although only GMS2 version asset was updated, all scripts without "_zlib" postfix in the name should be fully GMS1 compatible.

    Also I have created "FastCrypt Ultra" GUI tool which can be used for encrypt/decrypt various files.
    This tool uses two scripts
    1) file_fast_crypt_ultra_zlib() for encrypt/decrypt with compression
    2) file_fast_crypt_ultra() for encrypt/decrypt without compression.
    So the files compressed by "FastCrypt Ultra" tool can be later decompressed in your game using these scripts.
    As the tool the result file processing time, it can be used to check file encryption and decryption performance.
    Please note, this tool was compiled using YYC compiler, which is much faster than the VM compiler.

    [​IMG]
     
  22. 2Dcube

    2Dcube Member

    Joined:
    Jun 23, 2016
    Posts:
    384
    This is really great! Thanks so much.

    However, I have an issue and I'm not sure if it's because of my code, GMS2 or your asset.
    I use file_fast_crypt_ultra at the start of the game to decrypt a text file with json string.
    Then I decode the json. However, sometimes the json will be corrupt, sometimes not. Strangely this usually happens without changes to the file.
    For example if I start up the game a few times in a row, after a couple times suddenly the json will be corrupt, even though the file shouldn't have changed.

    Any idea? I'm encrypting/decrypting into the same file, should I use a different output file?
    Also I am doing this with 2 different files at the same time (overall save data and some other thing that is used less frequently). Usually the problem happens with the 2nd file but not always.

    Sample code:
    Code:
    var filename = "save.dat";
    if file_exists(filename)
    {
        // decrypt
        file_fast_crypt_ultra(filename,filename,false,"<encryptionkey>");
       
        var file = file_text_open_read(filename);
        var json = file_text_read_string(file);
        file_text_close(file);
       
        var map = json_decode(json);
       
        if map != -1
        {
             // read map entries...
        }
        else
              show_debug_message("JSON CORRUPT");
    }
     
  23. 2Dcube

    2Dcube Member

    Joined:
    Jun 23, 2016
    Posts:
    384
    Bumping to ask if you have any idea what the problem might be with encryption corrupting json.
     
  24. acidemic

    acidemic Member

    Joined:
    Jul 23, 2016
    Posts:
    115
    Currently I don't have any Ideas why your file gets randomly corrupted, so I can suggest you two options to try:

    1) Decrypt to a different temporary output file, which you will delete after it is not anymore required.

    2) Create a modified version of the script 'file_fast_crypt_ultra'so you can export the decrypted data directly to a string variable instead of a file.

    First, copy the script 'file_fast_crypt_ultra' to a new script, let's name it 'file_fast_crypt_ultra_mod' for example.

    Then replace the following lines at the end of the new script after the last '}':
    Code:
    buffer_save(_file_buffer, _filename_out); // Saving processed buffer into the output file
    buffer_delete(_file_buffer); // Removing buffer from memory
    
    //show_debug_message(string(filename_out));
    return 1;
    
    with this:

    Code:
    var _str_return = buffer_read(_file_buffer, buffer_string); // Send buffer to a string variable
    buffer_delete(_file_buffer); // Removing buffer from memory
    return _str_return; // Return processed buffer string
    
    in this case you will be able to use the following in your code:
    Code:
    var json = file_fast_crypt_ultra_mod(filename,filename,false,"<encryptionkey>");
    Of course second 'filename' argument will not be required in this case anymore, so you can pass any blank value into that argument or properly cleanup the new script 'file_fast_crypt_ultra_mod' to not use it anymore.
     
  25. acidemic

    acidemic Member

    Joined:
    Jul 23, 2016
    Posts:
    115
    To try debugging the problem when the JSON is corrupted, I can suggest you to check the contents of the decrypted JSON file to see what can be wrong with its contents.
     
    2Dcube likes this.
  26. 2Dcube

    2Dcube Member

    Joined:
    Jun 23, 2016
    Posts:
    384
    Thanks for the suggestions. I tried some things and it appears that when saving the file it would not always save the encrypted version if I used the same filename. So the file would just be readable, and then when trying to load it it would attempt decrypt and think the json is corrupt.
    I'm now saving into filename1, then encrypting it into filename2, and then deleting filename1. So far it seems to work without problems!

    Maybe I'll try your suggestion with strings later, as that might be better than creating and deleting files.
     

Share This Page