【问题标题】:Libsodium "Call to undefined function sodium_randombytes_buf" [closed]Libsodium“调用未定义函数 sodium_randombytes_buf”[关闭]
【发布时间】:2017-09-14 09:53:51
【问题描述】:

尝试遵循示例here,但它给了我

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

最重要的是,密钥对似乎正在生成奇怪的字符串,例如:

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

这正常吗?

这是我的代码

<?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);

【问题讨论】:

  • 你需要在他们的文件中要求你需要
  • 这是一个扩展

标签: php libsodium


【解决方案1】:

没有sodium_randombytes_buf()这样的功能,示例中的代码使用\Sodium\randombytes_buf()

编辑:

来自错误历史: "sodium_randombytes_* 符号已被删除一段时间,因为 PHP 现在提供了类似的功能,但没有此扩展"

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

【讨论】:

  • 他们在新版本中使用了前缀sodium_* 而不是命名空间
  • 您需要提供您的代码进行审核。
  • 好的。更新了问题内容
  • 看看我编辑的答案。
  • 所以可以使用random_bytes() php 内置函数吗?从密钥对生成的奇怪的kÿòjƒFDú{î—4]F◊î¸˜ßˆu…®_•A∞+ 字符串呢?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-24
  • 2012-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-28
相关资源
最近更新 更多