How can I encrypt my saved data so that players of the app can not (at least can not very easily) change the values of the game etc. using SB gamehacker, game killer, game guardian?
I am using loadsave library.
How can I encrypt my saved data so that players of the app can not (at least can not very easily) change the values of the game etc. using SB gamehacker, game killer, game guardian?
I am using loadsave library.
How are you saving the data? Json, SQL etc?
If it’s json, an easy way would be to just encrypt the json string itself prior to saving it, and then decrypting it whenever you need to open it again:
https://coronalabs.com/blog/2013/06/11/tutorial-using-the-openssl-plugin/
In places where you see “text” in that tutorial, you would put your json string, and where you see “key” you would just put some other string as a key (like any good password I would use a mix of upper/lower case, numbers and symbols).
This is a quick example, I haven’t tested it so there might be the odd typo:
local openssl = require( "plugin.openssl" ) local cipher = openssl.get\_cipher ( "aes-256-cbc" ) local json = require("json") local myPassword = "5]:-a9Ya5H(;" local myTable = { unlockedAllLevels = true, numberOfGems = 9, numberOfGoldCoins = 527, } local function saveEncryptedData(tableName, fileName) --turn table into json string local myJsonString = json.encode(tableName) --encrypt that json string local encryptedData = cipher:encrypt ( myJsonString, myPassword ) --save to a file local path = system.pathForFile(fileName, system.DocumentsDirectory ) local file = io.open(path, "w") file:write(encryptedData) io.close(file) end local function loadEncryptedData(filename) local path = system.pathForFile( filename, system.DocumentsDirectory ) -- will hold contents of file local contents --predeclare file variable local file -- io.open opens a file at path. returns nil if no file found if path then file = io.open( path, "r" ) end --if file could be opened then proceed if file then -- read all contents of file into a string contents = file:read( "\*a" ) io.close( file ) -- close the file after using it else --if file could not be opened, then set contents to be an empty table json string contents = "[]" end --decrypt the string that we have retrieved local decryptedData = cipher:decrypt ( contents, myPassword ) --then turn json string back into a lua table local newTable = json.decode(decryptedData) --and return the table return newTable end --call this function to save "myTable" as an encrypted json string saveEncryptedData(myTable, "mySaveFile.json") --and call this when we want to load that data myTable = loadEncryptedData("mySaveFile.json")
Ok thanks. I will try that out.
How are you saving the data? Json, SQL etc?
If it’s json, an easy way would be to just encrypt the json string itself prior to saving it, and then decrypting it whenever you need to open it again:
https://coronalabs.com/blog/2013/06/11/tutorial-using-the-openssl-plugin/
In places where you see “text” in that tutorial, you would put your json string, and where you see “key” you would just put some other string as a key (like any good password I would use a mix of upper/lower case, numbers and symbols).
This is a quick example, I haven’t tested it so there might be the odd typo:
local openssl = require( "plugin.openssl" ) local cipher = openssl.get\_cipher ( "aes-256-cbc" ) local json = require("json") local myPassword = "5]:-a9Ya5H(;" local myTable = { unlockedAllLevels = true, numberOfGems = 9, numberOfGoldCoins = 527, } local function saveEncryptedData(tableName, fileName) --turn table into json string local myJsonString = json.encode(tableName) --encrypt that json string local encryptedData = cipher:encrypt ( myJsonString, myPassword ) --save to a file local path = system.pathForFile(fileName, system.DocumentsDirectory ) local file = io.open(path, "w") file:write(encryptedData) io.close(file) end local function loadEncryptedData(filename) local path = system.pathForFile( filename, system.DocumentsDirectory ) -- will hold contents of file local contents --predeclare file variable local file -- io.open opens a file at path. returns nil if no file found if path then file = io.open( path, "r" ) end --if file could be opened then proceed if file then -- read all contents of file into a string contents = file:read( "\*a" ) io.close( file ) -- close the file after using it else --if file could not be opened, then set contents to be an empty table json string contents = "[]" end --decrypt the string that we have retrieved local decryptedData = cipher:decrypt ( contents, myPassword ) --then turn json string back into a lua table local newTable = json.decode(decryptedData) --and return the table return newTable end --call this function to save "myTable" as an encrypted json string saveEncryptedData(myTable, "mySaveFile.json") --and call this when we want to load that data myTable = loadEncryptedData("mySaveFile.json")
Ok thanks. I will try that out.