Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AWS EC2 (beanstalk) PHP 7.2 ... Sodium ... Solution

AWS have published that their AMI with PHP 7.2 has sodium (cryptography).

Plainly (as at writing) it does not. There is no package available. There is no solution.

Have attempted installing etc, but it is a long way around and messy.

Instead, there is an excellent PHP 7.2 Polyfill, from the orignal authors - right here: https://github.com/paragonie/sodium_compat

Here's how to install it:

Step 1: Use Composer

In the root directory of the application (that will be zipped and uploaded) ... create a file called "composer.json", with the following content:

{
    "require": {
        "paragonie/sodium_compat": "*"
    }
}

Step 2: Include via autoload.php

Like this:

require_once "vendor/paragonie/sodium_compat/autoload.php";
 
$alice_kp = sodium_crypto_sign_keypair();
$alice_sk = sodium_crypto_sign_secretkey($alice_kp);
$alice_pk = sodium_crypto_sign_publickey($alice_kp);
$message = 'This is a test message.';
$signature = sodium_crypto_sign_detached($message, $alice_sk);
if (sodium_crypto_sign_verify_detached($signature, $message, $alice_pk)) {
    echo 'OK', PHP_EOL;
} else {
    throw new Exception('Invalid signature');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.