Using Libsodium in PHP Projects

A guide to using the libsodium PHP extension for modern, secure, and fast cryptography. Open Source.

You shouldn't need a Ph.D in Applied Cryptography to build a secure web application. Enter libsodium, which allows developers to develop fast, secure, and reliable applications without needing to know what a stream cipher even is.

After reading this brief electronic manual, you should...

  • Know what libsodium is, what features it has, and how to install it (both the library and the PHP extension from PECL).
  • Generally understand which cryptography tool to use for a specific scenario.
  • Be capable of writing production-quality code that uses libsodium.

Chapter 1 should explain what libsodium is, introduce some basic concepts, and guide you through installing libsodium and the PHP extension.

Chapter 2 aims to be a useful reference page for all the functions and constants exposed by libsodium.

Chapters 3 - 9 cover the various functions that libsodium offers, what their purpose is, and how to use them.

Chapter 10 contains "recipes": Example code that uses libsodium to satisfy a project requirement.

Table of Contents

  1. Introduction to Libsodium Development in PHP
  2. Quick Start Guide
  3. Random Data
  4. Utilities and Helpers
  5. Basic Secret-key Cryptography
  6. Basic Public-key Cryptography
  7. Hashing
  8. Password Hashing
  9. Advanced Libsodium Features
  10. Recipes