Damn, seemed I was a little confused, we can only do one way encryption in Corona, the below would encrypt it, but decrypting can’t be done.
It may be useful for booleans or simple
[lua]require “CiderDebugger”;
local crypto = require(“crypto”)
display.setStatusBar(display.HiddenStatusBar)
_W = display.contentWidth / 2
_H = display.contentHeight / 2
myGameSettings = {}
myGameSettings.highScore = 1000
myGameSettings.soundOn = true
myGameSettings.musicOff = true
myGameSettings.playerName = “Barney Rubble”
deviceName = ( system.getInfo( “name” ) ) – “CraftyDeanos iPhone”
masterKey = “RandomStuff” – Random key
uniqueKey = crypto.hmac( crypto.md5, deviceName, masterKey) – encrypts phone name against masterKey
function encryptTableData()
myGameSettings.highScore = crypto.hmac( crypto.md5, myGameSettings.highScore, uniqueKey)
myGameSettings.soundOn = crypto.hmac( crypto.md5, tostring(myGameSettings.soundOn), uniqueKey)
myGameSettings.musicOff = crypto.hmac( crypto.md5, tostring(myGameSettings.musicOff), uniqueKey)
myGameSettings.playerName = crypto.hmac( crypto.md5, myGameSettings.playerName, uniqueKey)
text = display.newText(myGameSettings.highScore, 0, 0, native.systemFont, 10)
text = display.newText(myGameSettings.soundOn, 0, 20, native.systemFont, 10)
text = display.newText(myGameSettings.musicOff, 0, 40, native.systemFont, 10)
text = display.newText(myGameSettings.playerName, 0, 60, native.systemFont, 10)
end
encryptTableData()[/lua]
You say about users being able to amend fields to access content, do you have IAP’s with the JSON file showing the boolean true/false?
If so I use the following to check if the IAP’s have been purchased which creates a random file name when IAP is purchased and on boot it checks if this file is present and sets a boolean to true/false depending on the outcome.
[lua]isPro = false – if true then adverts disabled
– call this function when purchase is made
function writeproFileAds()
local deviceName = ( system.getInfo( “name” ) ) – phones name eg ‘deans iphone’
local cryptoKey = “SuperRandomHashKey” – key to hash against
local fileName = crypto.hmac( crypto.md5, deviceName, cryptoKey)
local path = system.pathForFile( fileName, system.DocumentsDirectory )
file = io.open( path, “w” ) – creates a file with the hash as its title
file:write( “Hey, I just bought you, and this is crazy, Heres my credit card number, Charge me maybe?” )
io.close( file )
isPro = true – changes isPro value to true
banner:release() – remove adverts
end
– call this function on application boot
function checkPro()
local deviceName = ( system.getInfo( “name” ) ) – phones name eg ‘deans iphone’
local cryptoKey = “SuperRandomHashKey”
local fileName = crypto.hmac( crypto.md5, deviceName, cryptoKey)
local path = system.pathForFile( fileName, system.DocumentsDirectory )
local file = io.open( path, “r” ) – checks if it can read the file
if file then --sets isPro to true if the file is readable.
isPro = true
io.close( file )
end
end[/lua] [import]uid: 62706 topic_id: 30493 reply_id: 122195[/import]