2

I really don't now what i have to do. I tried a install anothers libsodium's versions but i had problems with Modules. Hope you can help me, because i don't know if i'm using the functions correctly...

phpinfo has returned that libsodium is enabled, when i try a code like that:

var_dump([
    SODIUM_LIBRARY_VERSION,
    SODIUM_LIBRARY_MAJOR_VERSION,
    SODIUM_LIBRARY_MINOR_VERSION
]);

it shows this:

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

but... if i try this:

$kyp = sodium_crypto_kx_keypair();
$pub = sodium_crypto_kx_publickey($kyp);
$pri = sodium_crypto_kx_secretkey($kyp);

print_r($pub);

echo "<br/>";
echo "<br/>";
echo "<br/>";
echo "<br/>";
echo "<br/>";

print_r($pri);

the webpage shows:

�����gP�v� �zGG��I34���~%�b




�+��B�;��k{C��G�8��a��8S��`

PS: I'm using Laragon with PHP 7.2.11 in Windows 10

Moshe Katz
  • 15,992
  • 7
  • 69
  • 116

1 Answers1

2

Your code is working properly. The thing you are missing is that sodium functions will return data in binary format. If you want to print the key data, you need to convert it in to hex, like this (as shown in the documentation):

$keypair = sodium_crypto_kx_keypair();
$secret = sodium_crypto_kx_secretkey($keypair);
$public = sodium_crypto_kx_publickey($keypair);
printf("secret: %s\npublic: %s", bin2hex($secret), bin2hex($public));
Moshe Katz
  • 15,992
  • 7
  • 69
  • 116
PrashantAjani
  • 376
  • 3
  • 6