Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Owner

@defuse defuse May 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the include/require need to happen before this statement will work?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Namespace imports go at the top.


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require file_exists(__DIR__.'/../vendor/autoload.php')
    ? __DIR__.'/../vendor/autoload.php'
    : __DIR__.'/../../../autoload.php'
;

More simple?


$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 @@ -27,5 +27,8 @@
},
"require-dev": {
"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