halite: Fatal error with Sodium\hex2bin

Our PHP application is working correctly with Halite 1.0 on PHP 5.6 and corresponding Libsodium and PECL Libsodium.

Recently, we started migrating our application to Halite v3.2.0, and we are receiving error, as below,

Fatal error: Uncaught Error: Call to undefined function Sodium\hex2bin() in /home/uatpgsw/app/includes/halite-v320/src/KeyFactory.php:676 Stack trace: #0 /home/uatpgsw/app/includes/halite-v320/src/KeyFactory.php(587): ParagonIE\Halite\KeyFactory::loadKeyFile(‘/home/uatpgsw/g…’) #1 /home/uatpgsw/public_html/index.php(267): ParagonIE\Halite\KeyFactory::loadEncryptionKeyPair(‘/home/uatpgsw/g…’) #2 {main} thrown in /home/uatpgsw/app/includes/halite-v320/src/KeyFactory.php on line 676

Our dev system has:

  • PHP v7.0.26
  • Libsodium: v1.0.9
  • PECL libsodium v2.0.10

When I run the following:

<?php var_dump([ SODIUM_LIBRARY_MAJOR_VERSION, SODIUM_LIBRARY_MINOR_VERSION, SODIUM_LIBRARY_VERSION ]); ?>

the response is as follows:

array(3) { [0]=> int(9) [1]=> int(6) [2]=> string(6) "1.0.14" }

Please share, if I am missing something or do we specifically need to use the older versions like PECL Libsodium 1.0.6 / 2.0.4, along with PHP v7.0 and Libsodium v1.0.9, as documented in https://github.com/paragonie/halite?

thank you

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 20 (7 by maintainers)

Most upvoted comments

As the auto loader code, will include this src/HiddenString.php file, do i still try to manually attempt, to include this, or some other error scenario?

You need a use statement, or to refer to it by its fully qualified class name (ParagonIE\Halite\HiddenString).

While I donot use composer, and since, we keep libraries, outside webroot, I did change the $basedir, to reflect the correct path.

Use composer.

Alternatively, make sure you install this library too, which is listed in the require block in composer.json.

If you’re on PHP 7.2, you shouldn’t need anything from PECL.

The manual entry was auto-generated. There is no length argument.

If ParagonIE\Halite\Halite::isLibsodiumSetupCorrectly() does not return TRUE, install PECL libsodium again just to be sure.

Happy to hear it. 👍

Uhhhh, what. sodium_memzero() must exist or else something screwy is going on. Can you run ParagonIE\Halite\Halite::isLibsodiumSetupCorrectly(true) and paste the output? (Note, use three backticks followed by a newline to open a code block, and then follow it up with the same thing.)

```
code
```

Does Halite v3.2.0 support PHP v7.1 Branch?
if so, which versions of Libsodium and PECL Libsodium, do I use w.r.t. latest minor version of PHP v7.1 Branch?

Our supported versions are in this table on the README: https://github.com/paragonie/halite#installing-halite

Alternatively, if we have to choose PHP v7.2.0, that is released a week before, only Halite 4 will be the option know?

No, I’m fairly sure Halite 3 will work on PHP 7.2, but you’ll be better served with version 4, which will be supported when support for versions 2 and 3 are dropped.

PECL libsodium as of version 2 no longer uses namespaces but underscore functions. When you use the correct version of Halite this should work as expected. https://github.com/paragonie/halite#installing-halite

PHP 7.0 is reaching end of life soon, you should upgrade to PHP 7.1 or better PHP 7.2 which has Libsodium build-in (2.0, so remember to use the underscored function names).

Secondly, you shoudn’t hack into Halite as this may cause problems with interoperability.