SQL encryption (SQLite)

I want to encrypt the specific data that I want in the tables.

For instance,

I need something like this:

update mytable set column1 = encrypt(column1, "key") where condition; 

and this:

 select decrypt(column1, "key") from mytable where condition; 

Simple any built-in SQL function in SQLite to execute this?

I have a Java function for encrypt () and decrypt (), I need to massage the encryption of the column of the table, and it will be too slow if I read the column, apply this function and then write back. Please inform.

Thanks in advance.

+4
source share
1 answer

SQLite has the ability to provide its own functions - create_function sqlite function that you can use in your SQL statement.

So, I would look for create_function in java, for example: http://ppewww.physics.gla.ac.uk/~tdoherty/sqlite/javasqlite-20050608/doc/SQLite/Database.html or here is even an example http: // www .daniweb.com / software-development / java / threads / 221260

For example, in python it looks like this (an example is taken from http://docs.python.org/library/sqlite3.html Connection.create_function)

 import sqlite3 import md5 def md5sum(t): return md5.md5(t).hexdigest() con = sqlite3.connect(":memory:") con.create_function("md5", 1, md5sum) cur = con.cursor() cur.execute("select md5(?)", ("foo",)) print cur.fetchone()[0] 

Or: http://www.sqlite.org/c3ref/create_function.html

+1
source

Source: https://habr.com/ru/post/1385657/


All Articles