From 58aa547fd214103d4931b4e85f57d62c7c8122f6 Mon Sep 17 00:00:00 2001 From: Jayr Alencar Date: Thu, 5 May 2016 13:18:49 -0300 Subject: [PATCH] Fixing error in the usage of initializations vector --- CHANGELOG.md | 3 +++ package.json | 4 ++-- sqlite.js | 4 ++-- test/app.js | 21 +++++++++++---------- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0d30ed..e1dd0da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change Log This change log is started in 0.3.2; +## 0.3.5 (2016-05-05) +- Fixing error in the usage of initializations vector + ## 0.3.4 (2016-04-28) - Using algorithm and password in pvDecrypt - Using algorithm and password in pvEncrypt diff --git a/package.json b/package.json index 50ff710..d601407 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "encrypt", "decrypt" ], - "version": "0.3.4", + "version": "0.3.5", "author": { "name": "Jayr Alencar", "email": "jayralencarpereira@gmail.com", @@ -33,7 +33,7 @@ "url": "git+https://github.com/JayrAlencar/sqlite-cipher.js" }, "dependencies":{ - "sqlite-sync":"*", + "sqlite-sync":"latest", "crypto-js":"3.1.5" }, "license": "MIT", diff --git a/sqlite.js b/sqlite.js index c2c78f3..5750f3e 100644 --- a/sqlite.js +++ b/sqlite.js @@ -49,7 +49,7 @@ sqlite.prototype.pvDecrypt = function(buffer, algorithm, password){ algorithm = algorithm || this.algorithm; password = password || this.password; if(this.iv){ - var decipher = crypto.createDecipher(algorithm,password,{iv:this.iv}); + var decipher = crypto.createDecipheriv(algorithm,password,this.iv); }else{ var decipher = crypto.createDecipher(algorithm,password); } @@ -69,7 +69,7 @@ sqlite.prototype.pvEncrypt = function(buffer, algorithm, password){ algorithm = algorithm || this.algorithm; password = password || this.password; if(this.iv){ - var cipher = crypto.createCipher(algorithm,password, {iv: this.iv}); + var cipher = crypto.createCipheriv(algorithm,password, this.iv); }else{ var cipher = crypto.createCipher(algorithm,password); } diff --git a/test/app.js b/test/app.js index cc8aaf4..e486c2a 100644 --- a/test/app.js +++ b/test/app.js @@ -4,11 +4,12 @@ var sqlite = require('../sqlite.js'); //requiring // sqlite.change('test/Database.rec','88560848','myPass','aes-256-ctr','camellia-256-cfb1'); // To use initialization vector -sqlite.iv = '13ewr3iJ'; +sqlite.iv = "1234567890123456"; +var password = "12345678901234567890123456789012"; //Connecting - (databaseFile, [password], [algorithm]) try{ - sqlite.connect('test/Database.rec','myPass','camellia-256-cfb1'); + sqlite.connect('test/Database.rec',password,'aes-256-cbc'); }catch(x){ console.log(x) } @@ -30,16 +31,16 @@ function concat(a,b){ } //Add your function to connection -sqlite.create_function(concat); +// sqlite.create_function(concat); -// Use your function in the SQL -console.log(sqlite.run("SELECT ID , concat(ID, NAME) as concat FROM COMPANYS;")); +// // Use your function in the SQL +// console.log(sqlite.run("SELECT ID , concat(ID, NAME) as concat FROM COMPANYS;")); -//Decrypting database file -sqlite.decrypt("test/Database.rec","test/decrypted.db", 'myPass'); +// //Decrypting database file +// sqlite.decrypt("test/Database.rec","test/decrypted.db", 'myPass'); -//Encrypting database file -sqlite.encrypt("test/decrypted.db","test/reencrypted.rec", 'myPass',"bf",{iv: "ads343ef"}); +// //Encrypting database file +// sqlite.encrypt("test/decrypted.db","test/reencrypted.rec", 'myPass',"bf",{iv: "ads343ef"}); -// Closing connection +// // Closing connection sqlite.close(); \ No newline at end of file