Skip to content

Commit 5176f5a

Browse files
authored
Merge pull request #342 from chriseskow/generate-key-cli
[WIP] Add command line script for generating new keys
2 parents 0a4ed78 + 6c01bf2 commit 5176f5a

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

bin/generate-defuse-key

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use Defuse\Crypto\Key;
5+
6+
foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {
7+
if (file_exists($file)) {
8+
require $file;
9+
break;
10+
}
11+
}
12+
13+
$key = Key::createNewRandomKey();
14+
echo $key->saveToAsciiSafeString(), "\n";

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@
2828
"require-dev": {
2929
"phpunit/phpunit": "^4|^5",
3030
"nikic/php-parser": "^2.0|^3.0"
31-
}
31+
},
32+
"bin": [
33+
"bin/generate-defuse-key"
34+
]
3235
}

docs/Tutorial.md

+5-10
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,12 @@ Eve is a good database administrator, but she might have incentive to steal the
100100
data from the database. They want to keep some of the web application's data
101101
secret from Eve.
102102

103-
In order to do that, Alice will write a script that generates a random
104-
encryption key and prints it to standard output:
105-
106-
```php
107-
<?php
108-
// generate-key.php
109-
use Defuse\Crypto\Key;
110-
111-
$key = Key::createNewRandomKey();
112-
echo $key->saveToAsciiSafeString();
103+
In order to do that, Alice will use the included `generate-defuse-key` script
104+
which generates a random encryption key and prints it to standard output:
113105

106+
```sh
107+
$ composer require defuse/php-encryption
108+
$ vendor/bin/generate-defuse-key
114109
```
115110

116111
Alice will run this script once and save the output to a configuration file, say

0 commit comments

Comments
 (0)