Skip to content

Commit

Permalink
Merge pull request #342 from chriseskow/generate-key-cli
Browse files Browse the repository at this point in the history
[WIP] Add command line script for generating new keys
  • Loading branch information
defuse authored May 18, 2017
2 parents 0a4ed78 + 6c01bf2 commit 5176f5a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
14 changes: 14 additions & 0 deletions bin/generate-defuse-key
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env php
<?php

use Defuse\Crypto\Key;

foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {
if (file_exists($file)) {
require $file;
break;
}
}

$key = Key::createNewRandomKey();
echo $key->saveToAsciiSafeString(), "\n";
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
"require-dev": {
"phpunit/phpunit": "^4|^5",
"nikic/php-parser": "^2.0|^3.0"
}
},
"bin": [
"bin/generate-defuse-key"
]
}
15 changes: 5 additions & 10 deletions docs/Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,12 @@ Eve is a good database administrator, but she might have incentive to steal the
data from the database. They want to keep some of the web application's data
secret from Eve.

In order to do that, Alice will write a script that generates a random
encryption key and prints it to standard output:

```php
<?php
// generate-key.php
use Defuse\Crypto\Key;

$key = Key::createNewRandomKey();
echo $key->saveToAsciiSafeString();
In order to do that, Alice will use the included `generate-defuse-key` script
which generates a random encryption key and prints it to standard output:

```sh
$ composer require defuse/php-encryption
$ vendor/bin/generate-defuse-key
```

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

0 comments on commit 5176f5a

Please sign in to comment.