`
auauau
  • 浏览: 170784 次
社区版块
存档分类
最新评论

给sqlite数据库加密的两种方法

阅读更多

一个是采用SQLCipher

Need to store sensitive information in your app? SQLCipher extends SQLite enabling transparent encryption and decryption of data using AES. Its source is available on Github.

SQLite is pluggable. Developers can create extensions and chain them into SQLite’s engine. Using this mechanism, SQLCipher embeds itself low enough in the stack to be transparent. As a developer, you simply issue queries as you normally would and all of the crypto is handled transparently.

 

SQLCipher’s author, Stephen Lombardo of Zetetic, has also released Cryptographically Secure File I/O a library that supports random access file IO on encrypted files.

 

另外一个

Strong Encryption for Cocoa / Cocoa Touch

AES is a strong encryption standard that has mostly replaced the aging DESstandard. AES is widely used and fairly secure encryption mechanism (but I am not an expert at cryptography by any stretch of the imagination; I’m trusting experts for that opinion). AES supports three different key sizes, 128, 192, and 256 (the larger the key, the more secure the encryption and the more processing power it takes to encrypt or decrypt). Apple uses AES-128 and AES-256 in several places in Mac OS X, including for Disk Image encryption. 

 

There are several public-domain implementations of AES. I chose a public domain implementation of AES by Philip J. Erdelsky to use as the basis some Objective-C categories that make encrypting and decrypting files and data using AES-256 easy.

The first category is on NSFileManager, and allows you to encrypt a file in the filesystem. It takes a file at a particular pathname, encrypts it using a passphrase, and then writes the encrypted contents to a new specified file location. This version has relatively low memory overhead, as it streams the data in chunks both for reading and writing, so only the chunk currently being encrypted is in memory. The category adds two methods to NSFileManager, one for encrypting, the other for decrypting. These methods are the best choice when your source data already exists in the file system, especially on the iPhone, because of how little memory it uses to do the work. Here is an example of using the category on NSFileManager to encrypt a file:

    NSError *error = nil;
    if (![[NSFileManager defaultManager] AESEncryptFile:@"/path/to/input file" toFile:@"/path/to/output file" usingPassphrase:@"My secret password" error:&error])
    {
        NSLog(@"Failed to write encrypted file. Error = %@", [[error userInfo] objectForKey:AESEncryptionErrorDescriptionKey]);
    }

There is also a category on NSData that will let you encrypt a chunk of data that’s already in memory. This version creates a new NSData object with the encrypted contents of the original NSData instance. If your data is already in memory, and you want an encrypted or decrypted version of it, then the NSDatamethods are the way to go. Here is an example of using encrypting an NSDataobject with AES:

    NSData *encryptedData = [data AESEncryptWithPassphrase:@"My secret password"];

Pretty easy, huh? Okay, now, this is a symmetric block cypher, it is not public-key encryption, so if you store your passphrase as a string in your application (as opposed to making the user enter it or storing it in the keychain) then you’re giving somebody the ability to decrypt your encrypted application data, so just be forewarned.

Also, I make no warranties about how secure this is. As far as I know, AES-256 has not been broken yet, however I cannot say for certaint that there are no weaknesses in the AES implementation I’ve used. I don’t see any obvious problems but I am not a cryptographer. I haven’t heard of any weaknesses in this particular implementation, but any use of this is completely at your own risk.

Here is a zip file containing the two categories and the AES implementation. Just add these to your Xcode project, include the appropriate headers, andencrypt away.

Oh, and, one more important thing: If you use this in an iPhone application that you plan to sell on the App Store, it may lengthen the review process, as you will have to declare that you are using encryption, and will likely have to create and upload a CCATS form and wait for Apple to review it before your app will go up for sale. Read the iTunes Connect Developer Guide for more information on CCATS and the process before deciding to use this in an iPhone application for sale, please.

UPDATE: Jim Dovey author of the terrific Output iPhone App, posted a category on NSMutableData in the comments to this post that uses the crypto libraries already available on the Mac and iPhone to do AES-256 encryption. According to Jim, this means you don’t need a CCATS form because Apple’s exporting the encryption code, not you, so check it out Thanks, Jim.

分享到:
评论

相关推荐

    SQLite数据库 加密解密工具

    描述中的"SQLite数据库加密解密小工具"应该是一个.NET库或应用程序,它提供了对SQLite数据库加密和解密的功能。这个工具可能使用了某种加密算法(如AES)对数据库文件进行加解密,确保数据在存储和传输过程中的安全...

    Qt中SQlite数据库加密SqliteCipher 操作实例,打开多个数据库,附着数据库跨库查询.zip

    SQLiteCipher是一种针对SQLite数据库的加密解决方案,它提供了一种安全的方法来存储敏感数据,同时保持与标准SQLite API的兼容性。 首先,SQLiteCipher是SQLite的一个分支,它在数据库文件级别提供了AES-256加密。...

    C#开发的WinForm---SQLite加密程序

    SQLite提供了两种加密方法:VFS层加密(如SQLCipher)和用户空间模块(USM)。在本例中,由于我们是“手写”加密程序,我们可能采用USM,这意味着我们需要自定义SQLite函数来进行加密和解密操作。 加密过程通常包括...

    Sqlite数据库的加密

    这里有两种方法: 1. **直接设置密码**: ```csharp SQLiteConnection cnn = new SQLiteConnection("Data Source=c:\test2.db"); cnn.SetPassword("password"); cnn.Open(); ``` 2. **使用...

    sqlite数据加密demo程序

    实现SQLite数据库加密的方法很多,例如SQLCipher、SQLite Encryption Extension (SEE)等。SQLCipher是一款流行的开源解决方案,它提供了一个安全的API,允许开发者在标准SQLite API之上进行加密操作。这个demo可能...

    一个完整版的数据库加密系统

    总的来说,这个压缩包提供的资料可能涵盖了SQLite数据库加密的多个方面,包括理论知识、编程接口、实际加密库和示例。对于开发者来说,这是一份非常宝贵的资源,可以帮助他们在自己的应用程序中实施安全的数据存储...

    C#连接加密的Sqlite数据库的方法

    如果SQLite数据库加密,我这里使用的一个管理工具叫SQLiteDeveloper,如下就可以加密数据库 , 如果在工具中不提供密码的情况下打开数据库,会给你错误提示如下: , 或者在C# 使用错误的密码也会给你错误提示: ...

    pb9通过odbc连接sqlite3数据库

    除了使用PowerBuilder进行连接外,压缩包中提到的“两个sqlite数据库管理工具”可能是用于创建、查看和管理SQLite数据库的实用程序,例如SQLite Studio或DB Browser for SQLite。这些工具可以帮助开发者直接与SQLite...

    sqlite crypt支持加密数据库

    总的来说,SQLite Crypt是SQLite数据库加密的一个强大工具,为敏感数据提供了可靠的保护。通过理解其工作原理、加密算法以及如何在实际项目中集成,开发者可以有效地增强他们的应用程序的安全性,保护用户的隐私和...

    Android 数据库加密

    为了解决这个问题,"sqlite-encrypt"应运而生,它是一种专门针对Android平台的SQLite数据库加密解决方案。 sqlite-encrypt库允许开发者在SQLite数据库上添加一层额外的安全保护,通过对数据库文件进行加密,确保...

    Delphi XE7 Android平台与PC端同步SQLite 数据库

    本文将详细讨论如何使用Delphi XE7在Android平台上与PC端同步SQLite数据库,以便实现数据的一致性和实时更新。 Delphi XE7是Embarcadero公司推出的一款强大的集成开发环境(IDE),支持Windows、iOS、Android等多个...

    android之利用SQLite实现登陆和注册

    它是Android SDK提供的一种方便创建和管理SQLite数据库的工具类。我们通常会创建一个继承自SQLiteOpenHelper的子类,例如名为`DatabaseHelper`的类,来处理数据库的创建、升级和版本管理。在`DatabaseHelper`中,...

    SQLite.Interop.dll x32 x64

    SQLite 内置了两种加密方式:SQLite Encryption Extension (SEE) 和 FTS5 嵌入式全文搜索引擎的 AES-256 加密。SEE 是一种商业授权的加密插件,提供高强度的数据加密;FTS5 的加密特性则是针对其全文索引部分的,...

    sqlite加密

    这两种方法都遵循相同的加密流程,但密钥长度不同,导致加密强度有所差异。AES算法的工作原理是对明文数据进行多次替换和混淆操作,使得原始数据无法被轻易破解。 除了AES加密,描述中提到的“字节取反”是一种简单...

    sqlcipher3.exe sqlcipher4.exe加密数据库可以打开

    Sqlite Cipher是SQLite数据库的一个安全增强版本,它提供了一种对存储在数据库文件中的数据进行加密的方法,确保数据在存储和传输过程中的安全性。 Sqlite Cipher是在SQLite基础之上添加了AES(高级加密标准)加密...

    Sqlite3重编译版本,支持Sqlite3_key和Sqlite3_rekey方法.rar

    这两个方法是关于数据库加密的关键功能,对于那些需要增强数据安全性的应用来说尤为重要。 `Sqlite3_key`方法允许在打开数据库连接时设置一个密钥。这个密钥用于加密和解密数据库内容,确保数据在存储时是加密的,...

    linux下c语言sqlite3数据库用户注册登录并查询字典

    SQLite3是一个轻量级、嵌入式的关系型数据库管理系统,适用于多种操作系统,包括Linux。本项目着重讲解如何用C语言实现用户注册、登录功能,并进行字典查询。 首先,你需要在Linux系统上安装SQLite3库,通常可以...

    sqlite3 加密

    总结来说,SQLite3的加密功能为开发者提供了一种方便且强大的方式来保护存储在数据库中的数据。通过使用`sqlite3_key()`和`sqlite3_rekey()`,我们可以确保即使数据库文件被非法获取,数据也依然保持安全。提供的...

Global site tag (gtag.js) - Google Analytics