Page 1 of 1

SQL Picture base64encode and aes encryption

Posted: Wed Mar 19, 2014 1:35 pm
by za_mic
Hi,

I am a first time poster, but have been a reader of this forums for some time now. I have search the forums for a solution, and have found many solution to the issues I had, but I can't find a solution to this issue I am having:

I have a problem inserting an encrypted base64encode picture into a sqlite db:

The following was tested and it is working:

base64encode and base64decode of picture - works - picuture is shown in new img object.(SAME CARD, no db).
aes encryption and decryption of base64encode data - works - picuture is shown in new img object. (SAME CARD, no db).
insert command to db of only base64encoded data and select command from db of base64encode data, and the decode of it - works - picture is shown in new img object.

The issue can be with the insert or the select(decrypt and decode) of the data, and I don't know where to look anymore (including forums and other resources). I have used the *b for the insert of the encrypted data,
but can't decrypt and decode it into the img field.

Break down of code:
//Encode
put base64encode(url("binfile:" & "pathtopicture")) into id_image

//Encrypt
encrypt id_image using "aes256" with password tPassword and salt tSalt
put it into id_image

//Insert
revExecuteSQL tDatabaseID, "INSERT INTO cust_load (picture) VALUES (:1)","*bid_image" (have tried *bvariablename and only variable name)


//select and display
put "SELECT picture from cust_load" into tSQL
put revQueryDatabase(tDatabaseID, tSQL) into tCursorID
put revDatabaseColumnNamed(tCursorID, "picture", "tImageData") into tErrorMsg

put tImageData into field "enc_image" --put encrypted data into a field to show the encrypted data

decrypt tImageData using "aes256" with password tPassword and salt tSalt -- decrypting the data
put it into test
put test into field "base64code" -- put the decrypted data into a field (should be the base64encoded data)

put base64decode(tImageData) into img "picture" --decode the data and put into image object

Please help!!! :-(

Thank so far for all the tips, tricks and solutions on this Forum.

Re: SQL Picture base64encode and aes encryption

Posted: Thu Mar 20, 2014 5:59 am
by Simon
Hi za_mic,
Welcome to the forum!

I take it you are on liveCode ver 6.6.x ?
Have you seen where it fails?
Is the encrypted data the same going in as coming out of the db? (I mean have you looked at the first few lines?)
What data type are you using when you create the table for the image?
After decrypt the base64 messed up?

Simon

Re: SQL Picture base64encode and aes encryption

Posted: Thu Mar 20, 2014 8:00 am
by za_mic
Hi Simon,

Thanks for the welcome and the reply.

Yes, I am using ver 6.6.x?

It looks as if it fails at the insert of the encrypted data. The total number of chars that get inserted is only 246, I've used blob, varchar, text and varbinary, but still no success.

But base64 data gets inserted.

So I think I might have find the solution:

1. base64encode picture
2. encrypt base64encoded data
3. base64encode the encrypted base64encoded data
4. Insert into DB

Will post the outcome.

Re: SQL Picture base64encode and aes encryption

Posted: Thu Mar 20, 2014 12:55 pm
by za_mic
......and it is working.

Working with photos that gets taken as well (and they don't get stored in the phone's gallery)

Steps are as follow:

1. base64encode the photo / picture
2. encrypt the base64encoded photo / picture
3. base64encode the encrypted data
4. insert it into the db