Saving an encrypted thing and loading it does not work!

Also, have you tested encryption and decryption without all the saving and restoring from file and tables parts?

i.e. Have you successfully:

  • encrypted a string
  • decrypted a string
  • printed the string to verify the decryption?

I’m asking because you do that, you can’t be sure the rest of your code will work.

Also, not doing this step wise makes the whole thing way more complicated to debug.

Yes I have. I did something like

local variable = “test”
print( variable )

local encryptedVariable = cipher:encrypt( variable, myPassword )
print(encryptedVariable) – came out nonsense

local decryptedVariable = cipher:decrypt( encryptedVariable, myPassword )
print( decryptedVariable ) – came out as “test”

I see you’re referring to an old thread.  I noticed the link in that thread is now gone.

OK.  Let me see what I can resolve.

Warning.  My answer will use SSK.  I simply don’t do long hand stuff like this. :frowning:

It sure would be nice if you attached a zip file with your test project as that would save folks the effort of remembering the build.settings settings, etc.

Don’t forget.  Always format code posts, no matter how short.

formatyourcode.jpg

Continuing to resolve issue.

I can attach the zip tomorrow.

And btw I know how to format the code snippets on PC but I am on mobile (can you do tuhat on mobile?).

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/05/encryptedPersistentData.zip

function tests.three( myPassword ) local myData = { name = "billy", age = 10, loves = "Corona and Games" } print( "DUMP OF ORIGINAL TABLE" ) for k,v in pairs( myData ) do print(k,v) end local encoded = json.encode( myData ) print( "JSON ENCODED: ", encoded ) local out = cipher:encrypt( encoded, myPassword ) print( "ENCRYPTED:", out ) -- Save and restore io.writeFile( out, "mydata.json" ) local restored = io.readFile( "mydata.json") print( "RESTORED: ", restored ) local out2 = cipher:decrypt( restored, myPassword ) print( "DECRYPTED:", out2 ) local decoded = json.decode( out2 ) print( "JSON DECODED: ", decoded ) print( "DUMP OF SAVED & RESTORED & DECODED TABLE" ) for k,v in pairs( decoded ) do print(k,v) end end

I never use mobile for posting to forums.  

Posts from mobile tend to be terribly formatted and I consider it rude not to make my posts super legible, but then I’m old and a stick in the mud.

I also find mobile useless for reading anything.  Again, old an stick in the mud.

Well, for now the only noticable difference between your code and mine is that you use io.writeFile and io.readFile and I use file:write and file:read… What are main differences in them?

Apples and oranges.  My io.writeFile() function uses file:write(), but it also does the opening, closing, and other stuff.

… or maybe that’s Oranges and Orange Seeds?

You can read the code to find out more:
https://raw.githubusercontent.com/roaminggamer/SSK2/master/ssk2/extensions/io.lua

I don’t know what to tell you other than my example works? 

I wanted to give you something that would solve the end problem, but I have to admit I was averse to using the code provided. 

I’m more of a problem solver and code writer, than a code debugger. 

Sorry!

OK. I have tested your code and implemented it in mine. Now it works flawlessly. Thank you so much för helping me.

Can I use your ssk2 library in my game that is in play store and has advertisement and might get iap purchases?

You may use SSK2 in any game or app, no credit statement, no cost, no strings, just use it.  May it speed up and simplify your dev process.  

Cheers,

Ed

Thanks a lot for everything.

Btw I must link the game for you when it is ready.

Actually, you should totally share a link here with everyone.  Good luck on the game.

If you need extra motivation while working, you can also post pics in the screenshot saturday thread:

https://forums.coronalabs.com/topic/45387-screenshotsaturday-post-your-screen-shots-here

It gets good feedback.

Yes, I will share it for everyone.