-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwd_script.js
26 lines (22 loc) · 928 Bytes
/
pwd_script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var forge = require('node-forge');
// Encrypts the message with the password as key
var encrypt = function(message, password) {
var salt = forge.random.getBytesSync(128);
var key = forge.pkcs5.pbkdf2(password, salt, 4, 16);
var iv = forge.random.getBytesSync(16);
var cipher = forge.cipher.createCipher('AES-CBC', key);
cipher.start({iv: iv});
cipher.update(forge.util.createBuffer(message));
cipher.finish();
var cipherText = forge.util.encode64(cipher.output.getBytes());
return {cipher_text: cipherText, salt: forge.util.encode64(salt), iv: forge.util.encode64(iv)};
}
// 'SmartCity' is the string that is being encrypted
var temp = encrypt('SmartCity', process.argv.slice(2)[0] || 'cat123');
var fs = require('fs');
fs.writeFile("pwd.txt", JSON.stringify(temp), function(err) {
if(err) {
return console.log(err);
}
console.log("The password file was created");
});