Skip to content

Commit 9af35a7

Browse files
author
Greg Bowler
authored
Sodium (#9)
* wip: working on sodium implementation * feature: initial sodium library implementation in object-oriented code for #7 * test: message classes * refactor: remove unused class * refactor: remove unused uri classes * test: cipher & init vector * test: key pair - 100% coverage * feature: encrypted uri * tweak: don't pass unused public key * tweak: remove unused import * test: fix tests after refactor * refactor: only use psr standard functionality * refactor: automatically generate key's bytes * refactor: secretbox sodium.php * refactor: secretbox sodium.php * refactor: secretbox sodium-lib-uri.php * refactor: secretbox remove unused references * refactor: no need to pass shared key as it's already in the uri * test: EncryptedMessage * test: tests passing * feature: do not pass key in uri * test: cipher text geturi * test: key * test: EncryptedUri - 100% coverage * tweak: output shared key with uri * tweak: use cipher test uri * stan: remove unused key * docs: update readme
1 parent 5cef809 commit 9af35a7

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

README.md

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Two-way encryption of messages for secure plain text transmission.
22
==================================================================
33

4-
When messages are passed between two systems via a public network, encryption tools must be used to secure the communication channel. The process of encrypting and decrypting a message is complex and prone to errors, but is simplified in this repository by providing the `Message` and `EncryptedMessage` class abstractions.
4+
When messages are passed between two systems via a public network, encryption tools must be used to secure the communication channel. The process of encrypting and decrypting a message is complex and prone to errors, but is simplified in this repository by providing the `PlainTextMessage` and `EncryptedMessage` class abstractions.
55

6-
Pass your plain text message to the `Message` constructor along with a private key, and you can call `getCipherText()` and `getIv()`. These two strings can be passed to the receiver by any communication mechanism, safe in the knowledge that the contents can not be read without the private key.
6+
Pass your secret message to the `PlainTextMessage` constructor along with a private key, and you can call `encrypt()` to convert it into an `EncryptedMessage`. An `EncryptedMessage` is represented by a Cipher and IV value via the `getCipherText()` and `getIv()` functions. These two strings can be passed to the receiver by any communication mechanism, safe in the knowledge that the contents can not be read without the private key.
77

8-
On the receiver, construct an `EncryptedMessage` with the incoming ciphertext, and the same private key and IV, and the original message can be read.
8+
On the receiver, construct another `EncryptedMessage` with the incoming cipher and IV, and the original message can be read using `decrypt()`
99

10-
The `URIAdapter` class can be used to convert from a `Message` to a URI query string, or from a URI to an `EncryptedMessage`.
10+
The `CipherText` class also exposes a `getUri()` function, for creating a pre-encoded URI. A URI with `cipher` and `iv` querystring parameters can be passed to the `EncryptedUri` class to decrypt back into a `PlainTextMessage`.
1111

1212
***
1313

@@ -32,20 +32,26 @@ The `URIAdapter` class can be used to convert from a `Message` to a URI query st
3232
`sender.php`:
3333

3434
```php
35-
$message = "Hello, PHP.Gt!";
35+
use \Gt\Cipher\Message\PlainTextMessage;
36+
use \Gt\Cipher\Message\EncryptedMessage;
37+
3638
$privateKey = "This can be any string, but a long random string is best.";
3739

38-
$message = new \Gt\Cipher\Message\PlainTextMessage($message, $privateKey);
39-
// Redirect to receiver.php, possibly on another server:
40-
header("Location: " . new \Gt\Cipher\CipherUri($message, "/receiver.php"));
40+
$message = new PlainTextMessage("Hello, PHP.Gt!");
41+
$cipherText = $message->encrypt($privateKey);
42+
header("Location: " . $cipherText->getUri("/receiver.php"));
4143
```
4244

4345
`receiver.php`:
4446

4547
```php
4648
// This key must be the same on the sender and receiver!
49+
use Gt\Cipher\EncryptedUri;
50+
4751
$privateKey = "This can be any string, but a long random string is best.";
48-
$cipher = new \Gt\Cipher\Message\EncryptedMessage($_GET["cipher"], $_GET["iv"], $privateKey);
49-
echo $cipher->getMessage();
52+
53+
$uri = new EncryptedUri($_SERVER["REQUEST_URI"]);
54+
$plainText = $uri->decryptMessage($privateKey);
55+
echo $plainText;
5056
// Output: Hello, PHP.Gt!
5157
```

0 commit comments

Comments
 (0)