let cpath = path.cString(using:String.Encoding.utf8)
let error = sqlite3_open(cpath!, &sqlite3dbConn)
if error != SQLITE_OK {
// Open failed, close DB and fail
NELog("DA - failed to open \(DB_FILE)!")
sqlite3_close(sqlite3dbConn)
return false
}
else
{
NDBLog("DA : \(DB_FILE) opened")
}
let licensePragma = ("PRAGMA cipher_license = \(licence);" as NSString).utf8String
var rc = sqlite3_exec(sqlite3dbConn, licensePragma, nil, nil, nil)
if (rc != SQLITE_OK) {
let errmsg = String(cString: sqlite3_errmsg(sqlite3dbConn))
print("Error with cipher_license: \(errmsg)")
return false
}
rc = sqlite3_key(sqlite3dbConn, (password as NSString).utf8String, Int32(password.utf8CString.count))
if (rc != SQLITE_OK) {
let errmsg = String(cString: sqlite3_errmsg(sqlite3dbConn))
NSLog("Error setting key: \(errmsg)")
}
let cipherLicense = ("PRAGMA cipher_license;" as NSString).utf8String
rc = sqlite3_prepare(sqlite3dbConn, cipherLicense, -1, &stmt, nil);
rc = sqlite3_step(stmt);
if (rc == SQLITE_ROW){
rc = sqlite3_column_int(stmt, 0);
sqlite3_finalize(stmt);
print("PRAGMA cipher_license; returned \(rc)");
if(rc == SQLITE_AUTH){
let errmsg = String(cString: sqlite3_errmsg(sqlite3dbConn))
print("Failed to apply license key: \(errmsg)")
sqlite3_close(sqlite3dbConn);
sqlite3dbConn = nil;
return false;
}
}
else {
let errmsg = String(cString: sqlite3_errmsg(self.sqlite3dbConn))
print("cipher_license: \(errmsg)")
}
let createTableQuery = ("CREATE TABLE IF NOT EXISTS t1(a,b);" as NSString).utf8String
rc = sqlite3_exec(self.sqlite3dbConn, createTableQuery, nil, nil, nil)
if (rc != SQLITE_OK){
let errmsg = String(cString: sqlite3_errmsg(self.sqlite3dbConn))
print("Failed to create table: \(errmsg)")
return false
}else {
let errmsg = String(cString: sqlite3_errmsg(self.sqlite3dbConn))
print("successfully created table: \(errmsg)")
}
this is hexdump result
I’m getting result 21 in sqlite3_key(sqlite3dbConn, (password as NSString).utf8String, Int32(password.utf8CString.count))
and result 101 in sqlite3_prepare(sqlite3dbConn, cipherLicense, -1, &stmt, nil);
what is the problem in this code?