Openssl and sqlite3

Hi guys!

 

I’m trying to encode my data before putting it in the database, like this:

local json = require("json") local sqlite3 = require("sqlite3") local openssl = require( "plugin.openssl" ) local cipher = openssl.get\_cipher ( "aes-256-cbc" ) local path = system.pathForFile( "game.db", system.DocumentsDirectory ) local db = sqlite3.open( path ) local myPassword = ""--my password local myTable = { --myData } --table to json local data = json.encode(myTable) --cripto i dati prima di memorizzarli local encryptedData = cipher:encrypt ( data, myPassword ) local query = string.format("INSERT INTO %s VALUES (NULL, %d, '%s');", tableName, num, encryptedData)

The fact is that some tables are saved and others do not.

 

The query fails.

Apparently the new encrypted string contains “[” or “]” characters that create problems…

 

Is there a way to prevent encrypted data from having problems with the query? One way to make this smooth…

Well… instead of using openssl (which  will require you to mark your app as using encryption for the Apple App store by the way), you could just use my obfuscation code in SSK2 and create a key without brackets.
 
https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/security/
 
It will be a small amount of work to grok and tweak, but it should sufficiently obfuscate the saved entries to make them unusable by anyone who tries to without your permission.
 
PS - To make this work w/o brackets, you’ll have to modify the module, but it should be as simple as removing the brackets from the default generation list.
 
https://github.com/roaminggamer/SSK2/blob/master/ssk2/security.lua
 
I think the change would be to make line 9 through 11:

letters = letters .. string.upper( letters ) .. "1234567890!@#$%^&\*()\_+-=`~ " .. ",.\<\>{}/?;:|" -- removed square brackets

Then, generate a new key and it should be good for use as documented

Thank you so much I did not know openssl required that mark  for the App store.

I tried your code. Coverage is more than enough for what I have to do.

If someone wanted to use the module without SSK I noticed he must add a local function to the module like:

local function shuffle( t, iter ) local iter = iter or 1 local n for i = 1, iter do n = #t while n \>= 2 do -- n is now the last pertinent index local k = math.random(n) -- 1 \<= k \<= n -- Quick swap t[n], t[k] = t[k], t[n] n = n - 1 end end return t end

Of course I found this after searching on ssk of roaminggamer. (No flour in my bag).

@roaminggamer  Thanks again for the support in this and other occasions I hope to return the favors

P.s. Of course I’ve tried with sqlite3 and it works in wonder

I use openSSL for SHA256 encryption and have always answered no to that question on iTunes.  So far (touch wood) then have never opened my data files to find unreadable content.  Just saying…

Well… instead of using openssl (which  will require you to mark your app as using encryption for the Apple App store by the way), you could just use my obfuscation code in SSK2 and create a key without brackets.
 
https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/security/
 
It will be a small amount of work to grok and tweak, but it should sufficiently obfuscate the saved entries to make them unusable by anyone who tries to without your permission.
 
PS - To make this work w/o brackets, you’ll have to modify the module, but it should be as simple as removing the brackets from the default generation list.
 
https://github.com/roaminggamer/SSK2/blob/master/ssk2/security.lua
 
I think the change would be to make line 9 through 11:

letters = letters .. string.upper( letters ) .. "1234567890!@#$%^&\*()\_+-=`~ " .. ",.\<\>{}/?;:|" -- removed square brackets

Then, generate a new key and it should be good for use as documented

Thank you so much I did not know openssl required that mark  for the App store.

I tried your code. Coverage is more than enough for what I have to do.

If someone wanted to use the module without SSK I noticed he must add a local function to the module like:

local function shuffle( t, iter ) local iter = iter or 1 local n for i = 1, iter do n = #t while n \>= 2 do -- n is now the last pertinent index local k = math.random(n) -- 1 \<= k \<= n -- Quick swap t[n], t[k] = t[k], t[n] n = n - 1 end end return t end

Of course I found this after searching on ssk of roaminggamer. (No flour in my bag).

@roaminggamer  Thanks again for the support in this and other occasions I hope to return the favors

P.s. Of course I’ve tried with sqlite3 and it works in wonder

I use openSSL for SHA256 encryption and have always answered no to that question on iTunes.  So far (touch wood) then have never opened my data files to find unreadable content.  Just saying…