Using sqlcipher with sqlite3 in Electron-Builder application - electron

Background
I am trying to encrypt my sqlite database using sqlite3 and sqlcipher in an Electron application.
On the sqlite3 npm page here
It says to install the build like this,
yarn add sqlite3#4.0.8 --build-from-source --sqlite_libname=sqlcipher
--sqlite=brew --prefix --runtime=electron --target=4.0.0 --dist-url=https://atom.io/download/electron
I have installed sqlcipher with home brew.
brew install sqlcipher
Problem Example
I am trying to create an encrypted database like this in my Electron application,
const sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('./src/encryptedDB.sql');
db.serialize(function() {
db.run("PRAGMA KEY = 'secret'");
db.run("PRAGMA CIPHER = 'aes-256-cbc'");
db.run('CREATE TABLE IF NOT EXISTS clients (info TEXT)');
var stmt = db.prepare('INSERT INTO clients VALUES (?)');
for (var i = 0; i < 10; i++) {
stmt.run('wunO Background Client Number - ' + i);
}
stmt.finalize();
});
This is not creating an encrypted database. I can open the file and see data inside of it.
Question
I am trying to figure out if this is a simple problem with my syntax or if maybe when the electron builder runs it's magic in the background, it is rebuilding sqlite and removing the sqlcipher build.
How do I create an encrypted sqlite build that will work on MacOS and Windows.

I can open the file and see data inside of it.
Since it's not asking for any type of passwords, then there must be problem with database creation. In the readme of Electron-builder it states that
To ensure your native dependencies are always matched electron version, simply add script "postinstall": "electron-builder install-app-deps" to your package.json.
Place the following line in your package.json and repeat the installation process again, this resolved the problem for me.
"postinstall": "install-app-deps",
Also, I have created a small Vue + Electron + Vuetify + SQLite (with Seqlize & Sqlcipher) starter kit that has all the things you need already setup. The source code to generate encrypted database can be found in src/renderer/models.js give it a look.
https://github.com/rizalishan/vue-electron-starter

Related

Electron builder works on development but not on install

I'm trying to follow other people who had a similar issue like this one
Electron-Builder include external folder I wish i could be more specific on what my problem is, the reason is that i dont know whats wrong.
I am making a react app which has a server with an sqlite db and im trying to use electron.js to make it into an installable/executable
here is my dummy repo https://github.com/Juan321654/electron_react_with_build_installer_sqlite_db the master branch was just how to make electron work with react, the server branch is the one that i need help with
you can clone and just do npm i, npm run start to launch executable. npm run build to build
the code works fine in development mode and even after i make the build project with electron i can launch the executable and it works fine and it reads the data from the database, but as soon as i take the dist folder out of the project to send to someone or install the software, it stops working and it loads the app, but it does not read the data from the server/db, I am not sure if its missing node modules or the server folder, or maybe if im missing some kind of command in my scripts in the package.json?

Electron Squirrel.Windows: How can I remove local app data on uninstall?

Currently I have an installer built with Squirrel.Windows. On uninstall, the application directory under:
C:\Users\Me\AppData\Local\MyApplicationDirectory
remains. I have tried using rimraf under the the --squirrel-uninstall hook to remove the directory, but it fails because the files are in use.
Here is what I have that is not working:
case '--squirrel-uninstall':
var myLocalAppData = "C:\\Users\\Me\\AppData\\Local\\MyApplication";
rimraf(myLocalAppData);
app.quit();
I have tried the following to no avail:
Using a setTimeout() to delay the rimraf(myLocalAppData) call
Using the maxBusyTries param in the rimraf options to continue retrying for 10 seconds if a EBUSY, ENOTEMPTY, or EPERM error code is encountered when trying to clean up the directory
Running app.exit() before the rimraf(myLocalAppData)
I know the NSIS installer provided by electron-builder properly cleans up the app data directory, but I cannot use it as I need a MSI to support machine wide installations via Group Policy Management.
Any help is appreciated!

Cannot use node-hid library in electron app

I had integrated OpenTok.js library for video call in my electron app, for which i want to use logitech device and to use it i need node-hid library using which my app can detect device.
I had done all the needful mentioned for using node-hid in Electron projects, package did get installed
but when i require it in my js file using :-
var HID = require('node-hid');
var devices = HID.devices();
And run my app , it gives an error
Error: Module version mismatch. Expected 50, got 51. So please help me
with this issue .
Thanks
Use electron-rebuild for rebuild modules for suitable for electron. Some node modules are not exactly suitable for electron, because electron uses it's own build of Node. So, electron-rebuild will sort out any incompatibility or functional issues of node modules we use. The recommended way it to add "postinstall": "electron-rebuild --force" line to scripts of package.json file.
One other thing, on linux when you run dev mode, you have to run the script as sudo. Otherwise it'll rise another issue like cannot open device with path...
hope this help someone... :)
I encountered this issue myself, and thought I would share the solution that worked for me. #Tharanga is correct - the recommended way to get around this is to include the below in package.json "scripts" section:
"postinstall": "electron-rebuild --force"
However, I have experienced inconsistent success with that approach.
Another approach is, after installing "node-hid", run this (if on mac):
.\node_modules\.bin\electron-rebuild
Or for Windows:
.\node_modules\.bin\electron-rebuild.cmd
Finally, if you are using webpack in your project, you must add this line to your webpack.config.js file (within module.exports block):
externals: {
"node-hid" : 'commonjs node-hid'
}
I hope this helps some folks in the future!

How to trigger the following 'sqlite3' command under iOS?

I need to recreate a SQLite database programmatically under iOS from a malformed database using this command. Which is original from: How to recover a corrupt SQLite3 database?
$ sqlite3 mydata.db ".dump" | sqlite3 new.db
or a equivalent command like this.
$ sqlite3 test.db '.dump' > dbbackup
Scenario: I need a function in my App which could detect the malformed Sqlite database and repair it self.
I used the sqlite3_backup- functions to recreate it, but the recreated database also malformed. But the database which was created with the help of the first command seems to be ok.
But the command is only for terminal and how can I trigger using iOS programmatically?
NB: Any other way to solve the problem also welcomed.

Creating laravel apps without internet connection

Does laravel 5.1 work without internet connection?
I like to create a laravel new application
when i execute laravel new test (with intenet connection) it works well;
but when i execute similar command in the same directory (new anotherName) without internet connection it doesn't work and the nest error message is shown
[GuzzleHttp\Exception\RequestException]
Error creating resource. [url] http://cabinet.laravel.com/latest.zip [type]
2 [message] fopen(http://cabinet.laravel.com/latest.zip): failed to open s
tream: php_network_getaddresses: getaddrinfo failed: Name or service not kn
own [file] /home/<Myname>/.composer/vendor/guzzlehttp/guzzle/src/Adapter/Str
eamAdapter.php [line] 367
Is there a solution because i can't work online always?
When you use the laravel installer it fetches the latest version from the server. One solution would be to initialise a Laravel project, then add it to git version control and then when offline checkout the project to a new folder. You'd have to manually choose a new app key (I think). You will also not be able to composer require or npm install any new packages while offline.
Once you have created it though it should run offline (unless your views are sourcing assets from, say, bootstrap or jQuery CDNs).
Composer 2+:
COMPOSER_DISABLE_NETWORK=1 laravel new myapp
Troubleshooting:
Check your composer version: composer --version - you may have to update to the latest version with composer self-update;
Check you have a global cache: echo $COMPOSER_HOME - you may have to create a ~/.composer and set export COMPOSER_HOME="${HOME}/.composer" to your ~/.bashrc or ~/.zshrc - don't forget to close and open your terminal to apply the changes;
If you get this error https://repo.packagist.org could not be fully loaded (Network disabled, request canceled: https://repo.packagist.org/packages.json), package information was loaded from the local cache and may be out of date, the laravel packages are not in the global cache. Run the command with internet enabled to download the files.

Resources