forked from GregOriol/PushFTP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encryptPassword.php
67 lines (57 loc) · 1.49 KB
/
encryptPassword.php
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* This script will encrypt passwords to use in pushftp.json
*/
/**
* Configuration
*/
define('BASE_PATH', __DIR__);
/**
* Base
*/
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . BASE_PATH);
set_include_path(get_include_path() . PATH_SEPARATOR . BASE_PATH);
/**
* Loading
*/
require_once('vendor/autoload.php');
require_once('vendor/load.php');
/**
* Main
*/
// Setting up command line parser
$parser = new \Console_CommandLine();
$parser->description = 'Encrypt passwords for pushftp.json';
$parser->version = '1.0';
$parser->addOption('password', array(
'long_name' => '--password',
'description' => "the password to encrypt",
'action' => 'Password'
));
$parser->addOption('key', array(
'long_name' => '--key',
'description' => "the key to use",
'action' => 'StoreString'
));
// Parsing command line
try {
$cli = $parser->parse();
// print_r($cli->options);
// print_r($cli->args);
} catch (\Exception $exc) {
$parser->displayError($exc->getMessage());
throw new \Exception("Error parsing command line", 1, $exc);
}
// Performing some checks
if ($cli->options['password'] === NULL || empty($cli->options['password']) ||
$cli->options['key'] === NULL || empty($cli->options['key'])) {
echo 'Missing arguments'."\n";
exit(1);
}
$pass = $cli->options['password'];
$key = $cli->options['key'];
echo "\n";
$encrypter = new \phpseclib\Crypt\AES();
$encrypter->setKey($key);
$pass_encrypt = $encrypter->encrypt($pass);
echo base64_encode($pass_encrypt)."\n";