Skip to content

Instantly share code, notes, and snippets.

@mikehains
Last active May 20, 2019 20:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikehains/08b61c621320f78a5f14f89ad3a5739f to your computer and use it in GitHub Desktop.
Save mikehains/08b61c621320f78a5f14f89ad3a5739f to your computer and use it in GitHub Desktop.
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