I’ve just become aware of a bug in my Load / Save table encryption when offline.
I use mime and open ssl to generate an encryption key.
If you save data when online, then go offline and try to load data, my app will sometimes freeze, not all the time though!
Any ideas on how to make this work when the user has no internet connection?, I’m lost on this one!
local openssl = require “plugin.openssl”
local cipher = openssl.get_cipher (“RC2-40-CBC”)
local mime = require ( “mime” )
— Load Table
if ( file ) then
local contents = file:read( “*a” )
local decryptedData = cipher:decrypt ( mime.unb64 ( contents ), deviceID )
local table = {}
if _G.encryptedSaveData then
table = json.decode( decryptedData );
else
table = json.decode( contents );
end
io.close( file )
return table
end
– Save Table —
if( file ~= nil ) then
local contents = json.encode( table )
local encryptedData = mime.b64 ( cipher:encrypt ( contents, deviceID ) )
if _G.encryptedSaveData then
file:write( encryptedData )
else
file:write( contents )
end
io.close( file )
return true
end