Asset - Scripts Fast & Secure File Encryption Scripts

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

  1. acidemic

    acidemic Member

    Joined:
    Jul 23, 2016
    Posts:
    112
    Encrypt / decrypt your files and game resources 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 several scripts which provide various encryption/encoding levels.
    • fast_file_key_crypt - Secure file encryption using fast "Vulkan" algorithm with secret 1152 bit key. Use this for best security!
    • 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.
    • fast_file_crypt - Very simple file encoding by shifting each byte by 128 bits.
    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:
    • Several scripts for fast / secure encryption.
    • Encryption using fast "Vulkan" 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.
    • Encrypted/encoded file size is exactly the same as the original file size.
    • 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.
    • Supported both GameMaker: Studio 1.x and 2.x.
     
    Last edited: Nov 11, 2017
  2. YellowAfterlife

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

    Joined:
    Apr 21, 2016
    Posts:
    2,382
    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:
    112
    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:
    112
    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:
    112
    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:
    790
    PNelly likes this.
  7. acidemic

    acidemic Member

    Joined:
    Jul 23, 2016
    Posts:
    112
    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:
    790
    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:
    112
    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:
    56
    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:
    301
    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:
    301
    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:
    301
    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:
    112
    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 at 2:41 PM

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice