Encryption in SQL (SQLite)



我想加密表中的特定数据…

例如,

我需要这样的东西:

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

:

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

是否有任何简单的内置SQL函数在SQLite完成这个吗?

我有一个用于encrypt()和decrypt()的Java函数,我需要批量加密表列,如果我读取列,应用函数然后回写,它将太慢。请建议。

SQLite有可能提供您自己的函数- create_function SQLite函数-您可以在SQL语句中使用。

所以我会寻找create_function在java中,例如:http://ppewww.physics.gla.ac.uk/~tdoherty/sqlite/javasqlite-20050608/doc/SQLite/Database.html这里甚至有一个例子http://www.daniweb.com/software-development/java/threads/221260

例如,在python中它看起来像这样(示例取自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]

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

最新更新