加密,解密Sqlite数据库

本文介绍如何使用SQLiteConnection类的ChangePassword()和SetPassword()方法来加密和解密Sqlite数据库。包括加密未加密数据库、更改加密数据库密码、解密已加密数据库以及设置新创建数据库的密码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

加密,解密Sqlite数据库

加密,解密Sqlite数据库

 

加密一个未加密的数据库或者更改一个加密数据库的密码,打开数据库,启动SQLiteConnection的ChangePassword() 函数

 

// Opens an unencrypted database

SQLiteConnection cnn = newSQLiteConnection("Data Source=c:\\test.db3");

cnn.Open();

 

// Encrypts the database. The connection remains valid and usable afterwards.

cnn.ChangePassword("mypassword");

解密一个已加密的数据库调用l ChangePassword() 将参数设为 NULL or "" :

 

// Opens an encrypted database

SQLiteConnection cnn = newSQLiteConnection("Data Source=c:\\test.db3;Password=mypassword");

cnn.Open();

 

// Removes the encryption on an encrypted database.

cnn.ChangePassword("");

要打开一个已加密的数据库或者新建一个加密数据库,在打开或者新建前调用SetPassword()函数

 

// Opens an encrypted database by calling SetPassword()

SQLiteConnection cnn = newSQLiteConnection("Data Source=c:\\test.db3");

cnn.SetPassword(newbyte[] { 0xFF, 0xEE, 0xDD, 0x10, 0x20, 0x30 });
cnn.Open();

// The connection is now usable

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值