Skip to content

Examples

Greg Bowler edited this page Apr 19, 2026 · 1 revision

The example/ directory is the quickest way to see the main workflows without building a larger application around them first.

Run an example from the repository root:

php example/01-encrypt-decrypt-message.php

Example index

  1. example/01-encrypt-decrypt-message.php Basic message encryption and decryption using PlainTextMessage and EncryptedMessage.
  2. example/02-encrypt-message-in-uri.php Embedding encrypted content into a URI and reading it back with EncryptedUri.
  3. example/03-share-key-between-processes.php Reconstructing the same shared key from a base64 string on the receiving side.

Repository root demos

There are also a few small scripts in the repository root which show the lower-level building blocks:

  • sodium.php: a direct libsodium demonstration with Cipher's exception types
  • sodium-lib.php: message encryption and decryption using the library API
  • sodium-lib-uri.php: URI-based encryption and decryption using the library API

Those scripts are useful when reading through the repository history or comparing the raw sodium calls with the higher-level abstractions.

What the examples are good for

The examples are especially helpful when we want to:

  • verify the expected string forms of keys, IVs, and cipher text
  • see the sender and receiver flow side by side
  • test the package quickly in a local shell

If you want the class and method list in one place, finish with API reference.

Clone this wiki locally