One extra question…
I’m using this feature to store login info so a user doesn’t have to login all the time.
After I got it all working, I deleted my table to test -relogin, if you do a secure_load and the file doesn’t exist, you get a lua crash.
Lights/ssk2/security.lua:43: bad argument #1 to ‘pairs’ (table expected, got nil)
stack traceback:
[C]: in function 'pairs’
Lights/ssk2/security.lua:43: in function 'encode’
Lights/ssk2/security.lua:74: in function 'getKeyString’
Lights/ssk2/extensions/table.lua:256: in function 'secure_load’
Lights/mainLogin.lua:50: in function '?'
?: in function 'dispatchEvent’
?: in function '_nextTransition’
?: in function <?:1494>
?: in function 'gotoScene’
Lights/main.lua:18: in main chunk
I did try to circumvent it by putting a 'test = security.loadkey command, and I was going to check if test was false (so it the key isn’t there, I would assume the secure table wasn’t) but I noticed it doesn’t return a value either.
While I can put in another few lines to check if the file exists I’d thought I’d mention it as returning nil on a non-existent file when using table.secure_load would be awesome
** Edit
I do see that you also have
- exists( path ) - Returns true if the file at path exists. Returns false otherwise.
So this edit wrapped around it should work fine.
if ssk.files.util.exists(system.pathForFile( "setup.json", system.DocumentsDirectory )) == true then print( "File Exists" ) else print( "File missing" ) end
** Edit End
The code I use is pretty much your example, but to pre-empt the question should it be asked…
local security = ssk.security local encoded2 = {} test= security.loadKey( "key.json") encoded2 = table.secure\_load("setup.json") local decodedEmail = security.decode( encoded2.Email ) local decodedPw = security.decode( encoded2.Pw )
As an aside, credit to you. While it isn’t intended to be a huge security protocol, its a great way to store local information and deter the casual hacker. The usage is so easy (as you can see above)!