Skip to content
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bd9f08f
wip: working on sodium implementation
Jul 18, 2022
a4c526a
feature: initial sodium library implementation in object-oriented code
Jul 19, 2022
8854ec9
test: message classes
Jul 19, 2022
161960e
refactor: remove unused class
Jul 19, 2022
9b77d53
refactor: remove unused uri classes
Jul 19, 2022
f120c9b
test: cipher & init vector
Jul 19, 2022
cd7d9ce
test: key pair - 100% coverage
Jul 19, 2022
58ec3b5
feature: encrypted uri
Jul 19, 2022
e58f802
tweak: don't pass unused public key
Jul 19, 2022
279a16e
tweak: remove unused import
Jul 19, 2022
84844a2
test: fix tests after refactor
Jul 19, 2022
a9d9e96
refactor: only use psr standard functionality
Jul 19, 2022
1958708
refactor: automatically generate key's bytes
Jul 19, 2022
3966239
refactor: secretbox sodium.php
Jul 20, 2022
cfc3eb6
refactor: secretbox sodium.php
Jul 20, 2022
c2bd42f
refactor: secretbox sodium-lib-uri.php
Jul 20, 2022
9c7d52a
refactor: secretbox remove unused references
Jul 20, 2022
07d76e0
refactor: no need to pass shared key as it's already in the uri
Jul 20, 2022
9479970
test: EncryptedMessage
Jul 20, 2022
1f7af32
test: tests passing
Jul 20, 2022
a3c3860
feature: do not pass key in uri
Jul 20, 2022
4f66f45
test: cipher text geturi
Jul 20, 2022
3a60947
test: key
Jul 20, 2022
20f1403
test: EncryptedUri - 100% coverage
Jul 20, 2022
2e144c6
tweak: output shared key with uri
Jul 20, 2022
13898e3
tweak: use cipher test uri
Jul 20, 2022
09c8c2c
stan: remove unused key
Jul 20, 2022
ff4d3e3
docs: update readme
Jul 20, 2022
8d07646
Merge branch 'master' of github.com:PhpGt/Cipher into sodium
Jul 20, 2022
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
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Two-way encryption of messages for secure plain text transmission.
==================================================================

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.
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.

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.
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.

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

The `URIAdapter` class can be used to convert from a `Message` to a URI query string, or from a URI to an `EncryptedMessage`.
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`.

***

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

```php
$message = "Hello, PHP.Gt!";
use \Gt\Cipher\Message\PlainTextMessage;
use \Gt\Cipher\Message\EncryptedMessage;

$privateKey = "This can be any string, but a long random string is best.";

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

`receiver.php`:

```php
// This key must be the same on the sender and receiver!
use Gt\Cipher\EncryptedUri;

$privateKey = "This can be any string, but a long random string is best.";
$cipher = new \Gt\Cipher\Message\EncryptedMessage($_GET["cipher"], $_GET["iv"], $privateKey);
echo $cipher->getMessage();

$uri = new EncryptedUri($_SERVER["REQUEST_URI"]);
$plainText = $uri->decryptMessage($privateKey);
echo $plainText;
// Output: Hello, PHP.Gt!
```