GameMaker (2.0 - 2.2.x)



You must be logged in to obtain assets


Did you want something that works like ds_map_secure_save, but cross-device and a bit less trivial to read? Have you ever asked "how do I encrypt this JSON so players can't snoop at the game files?"

This asset provides some very basic encryption using the popular RC4 (Arcfour) cipher, a fast cipher that provides basic security. Arcfour is appropriate for low-security purposes like scrambling save files. Arcfour is not suitable for high-security needs such as storing credit card information or perhaps passwords. Please understand the full implications of using encryption and pick appropriately for your security needs.

Arcfour encrypts data using a shared key. As long as you have this key, the data can be decrypted. Using the incorrect key causes garbled data to be returned. Think of it as similar to a password-protecting a file.

A typical use case would be to have a key provided as a string in your game. The game can use this key to write encrypted save files, and load and decrypt them again. But a human looking at the savefile (or included file) cannot read the data unless they have access to the key. NOTE: because it is possible to decompile a GM game to retrieve the key, do not assume that this method of encryption is 100% safe.

GMArcfour provides some functions to encrypt and decrypt data:

ds_map_arcfour_save(map, filename, key) This function works a lot like GM's built-in ds_map_secure_save(map, filename) but outputs an Arcfour encrypted file using the key that you provide. Use the same key when loading data to restore the data.

ds_map_arcfour_load(filename, key) This function works a lot like GM's built-in ds_map_secure_load(filename) but reads an Arcfour encrypted file previously saved with the above function, and uses the key that you provide to decrypt it. Use the same key as used to save the file to restore the data. Using an incorrect key will likely cause the function to return -1 as it would be unable to find valid data after decoding the file incorrectly.

ds_map_arcfour_save_buffer(map, key) This functions works a lot like GM's built-in ds_map_secure_save_buffer(map)

ds_map_arcfour_load_buffer(map, key) This function works a lot like GM's built-in ds_map_load_buffer(map)

arcfour_cipher(key, buffer) This function takes a buffer and a key, and returns a new buffer that has been ciphered with arcfour and the key. Because the cipher is symmetric, the same fuction is used for encoding and decoding data.

arcfour_encrypt(key, str) This function takes a string, and encrypts it using arcfour, returning a buffer containing the encrypted data

arcfour_decrypt(key, buff) This function takes a buffer, and decrypts it using arcfour, returning a string containing the decrypted data

arcfour_create_state(key) This is an internal function used by arcfour for creating the state space

End User Licence Agreement (EULA).

Age Rating: 4+


GMS2 - Version 1.0.0. Published June 7, 2020

Loading, please wait

Package contents

Loading, please wait

What is the issue?

Loading, please wait