-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moving to the crypto library from openssl
- Loading branch information
Kunal Nagar
committed
Apr 8, 2019
1 parent
a8094b2
commit fa68b12
Showing
4 changed files
with
89 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
var fs = require("fs"); | ||
var crypto = require("crypto"); | ||
var log = require("electron-log"); | ||
|
||
module.exports = class EncryptDecrypt { | ||
|
||
constructor(finalFile, filePath, passphrase) { | ||
this.finalFile = finalFile; | ||
this.filePath = filePath; | ||
this.passphrase = passphrase; | ||
} | ||
|
||
encrypt(data) { | ||
try { | ||
var cipher = crypto.createCipher('aes-256-cbc', this.passphrase); | ||
data.pipe(cipher).pipe(fs.createWriteStream(this.finalFile)); | ||
return { | ||
code: 200, | ||
message: "Encrypted" | ||
}; | ||
} catch(e) { | ||
throw new Error(e.message); | ||
} | ||
} | ||
|
||
decrypt(data) { | ||
try { | ||
var decipher = crypto.createDecipher("aes-256-cbc", this.passphrase); | ||
data.pipe(decipher).pipe(fs.createWriteStream(this.finalFile)); | ||
return { | ||
code: 200, | ||
message: "Decrypted" | ||
}; | ||
} catch (exception) { | ||
throw new Error(exception.message); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters