diff --git a/core/lib.rs b/core/lib.rs index e531a37b6..5b30f936d 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -1277,6 +1277,12 @@ impl Connection { std::fs::set_permissions(&opts.path, perms.permissions())?; } let conn = db.connect()?; + if let Some(cipher) = opts.cipher { + let _ = conn.pragma_update("cipher", format!("'{cipher}'")); + } + if let Some(hexkey) = opts.hexkey { + let _ = conn.pragma_update("hexkey", format!("'{hexkey}'")); + } Ok((io, conn)) } diff --git a/core/util.rs b/core/util.rs index 7d22106a6..e2f06c325 100644 --- a/core/util.rs +++ b/core/util.rs @@ -740,6 +740,10 @@ pub struct OpenOptions<'a> { pub cache: CacheMode, /// immutable=1|0 specifies that the database is stored on read-only media pub immutable: bool, + // The encryption cipher + pub cipher: Option, + // The encryption key in hex format + pub hexkey: Option, } pub const MEMORY_PATH: &str = ":memory:"; @@ -890,6 +894,8 @@ fn parse_query_params(query: &str, opts: &mut OpenOptions) -> Result<()> { "cache" => opts.cache = decoded_value.as_str().into(), "immutable" => opts.immutable = decoded_value == "1", "vfs" => opts.vfs = Some(decoded_value), + "cipher" => opts.cipher = Some(decoded_value), + "hexkey" => opts.hexkey = Some(decoded_value), _ => {} } }