2

Could anyone post code sample of how to open sqlcipher database? I guess that we need to call the key function in some way.

Dev77
  • 21
  • 1
  • 2

2 Answers2

2

Assuming you've installed SQLite.swift with SQLCipher support (if not, follow these instructions), you merely need to call the key function on your Database object:

import SQLite

let db = Database("path/to/ciphered.sqlite3")
db.key("your_key")

Once keyed, you can change the encryption key using rekey:

db.rekey("your_new_key")
leolobato
  • 2,359
  • 3
  • 32
  • 51
stephencelis
  • 4,954
  • 2
  • 29
  • 22
1

Take a look at SQLite.swift.

  • To see how to call the underlying sqlcipher functions. e.g. sqlite3_key(), see Cipher.swift
  • To see how to open a sqlcipher database in SQlite.swift with a key: CipherTests.swift
mhawke
  • 84,695
  • 9
  • 117
  • 138