Libsodium “Call to undefined function sodium_randombytes_buf” [closed]

坚强是说给别人听的谎言 提交于 2019-12-02 07:01:50

问题


Trying to follow the examples here, but it gives me

Fatal error: Uncaught Error: Call to undefined function sodium_randombytes_buf()

On top of that, the key pairs seems to be generating weird strings like:

kÿòjƒFDú{î—4]F◊î¸˜ßˆu…®_•A∞+.

Is that normal?

Here's my code

<?php

// send
$message = 'Hi, this is Alice';
$alice_to_bob_kp = sodium_crypto_box_keypair_from_secretkey_and_publickey(
    file_get_contents('./keys/sec-user-1_box_key.txt'),
    file_get_contents('./keys/pub-user-2_box_key.txt')
);
$nonce = sodium_randombytes_buf(SODIUM_CRYPTO_BOX_NONCEBYTES);
$ciphertext = sodium_crypto_box(
    $message,
    $nonce,
    $alice_to_bob_kp
);




// receive
$bob_to_alice_kp = sodium_crypto_box_keypair_from_secretkey_and_publickey(
    // $bob_box_secretkey,
    // $alice_box_publickey
    file_get_contents('./keys/sec-user-2_box_key.txt'),
    file_get_contents('./keys/pub-user-1_box_key.txt')
);
$nonce = sodium_randombytes_buf(SODIUM_CRYPTO_BOX_NONCEBYTES);
$plaintext = sodium_crypto_box_open(
    $ciphertext,
    $nonce,
    $bob_to_alice_kp
);
if ($plaintext === false) {
    die("Malformed message or invalid MAC");
}
die($plaintext);

回答1:


There is no such function as sodium_randombytes_buf() the code in the example uses \Sodium\randombytes_buf().

Edit:

From the bug history: "The sodium_randombytes_* symbols have been removed a while back, as PHP now provide similar functions without this extension"

Bug #74896 sodium's .h defines some functions without .c implementation



来源:https://stackoverflow.com/questions/46215938/libsodium-call-to-undefined-function-sodium-randombytes-buf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!