我想加密表中我希望的特定数据..
例如,
我需要这样的东西:
update mytable set column1 = encrypt(column1, "key") where condition;
还有这个:
select decrypt(column1, "key") from mytable where condition;
Is threre any simple in-built SQL function in SQLite to accomplish this?
我有一个用于加密()和解密()的Java函数,我需要批量加密表列,如果我读取该列,应用该函数然后写回,那么速度会太慢。请指教。
提前致谢。
最佳答案
SQLite 可以提供您自己的函数 - create_function sqlite 函数 - 您可以在 SQL 语句中使用它。
所以我会在java中寻找create_function,例如: 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]
关于sql - SQL 中的加密 (SQLite),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8457356/