sql - SQL 中的加密 (SQLite)

标签 sql sqlite encryption cryptography

我想加密表中我希望的特定数据..

例如,

我需要这样的东西:

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]

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

关于sql - SQL 中的加密 (SQLite),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8457356/

相关文章:

java - Java 中的 Flush PGP 加密 Bouncy CaSTLe 输出流

MySQL BEFORE INSERT 触发器将重复的主键插入转换为更新

java - JPA调用存储过程从2 db中选择数据

sqlite - 如何将特定行保持在订单底部?

android - 是否可以在不占用双倍数据库空间的情况下发布 Android 应用程序?

qt - QTcpSocket不会读取所有内容

sql - 在 Git 中存储 Drupal SQL

sql - SQL 的关系演算

Django-cms 和 SQLite 性能

c - c中的openssl aes_128_ctr