gpt4 book ai didi

PHP random_bytes 与钠整数错误

转载 作者:行者123 更新时间:2023-12-03 23:53:17 24 4
gpt4 key购买 nike

我试图在 IIS 的 PHP 7.2.7 中使用随机字节和钠加密字符串。

$nonce = random_bytes('SODIUM_CRYPTO_SECRETBOX_NONCEBYTES');


$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);

两者都返回此错误:
Uncaught TypeError: random_bytes() expects parameter 1 to be integer

但是这很好用
$key = random_bytes('SODIUM_CRYPTO_SECRETBOX_KEYBYTES');

谷歌似乎在这方面让我失望,我在搜索时没有找到任何帮助。

最佳答案

更新

取决于您如何配置 PHP。您可能没有正确访问常量。

请运行此脚本,看看它是否对您的问题有帮助。让我知道结果是什么。

$extenstion = FALSE;
$constants = FALSE;

echo '<pre>';

if(in_array('libsodium', get_loaded_extensions())){

$extenstion = TRUE;
echo 'Libsodium IS installed.<br>';

}else{

echo 'Libsodium IS NOT installed.<br>';

}

$constantsArray = get_defined_constants(true);

if(isset($constantsArray['libsodium']) && $constantsArray['libsodium']){

$constants = TRUE;

echo 'You HAVE predefined Libsodium constants.<br>';

}else{

echo 'You DO NOT have any predefined Libsodium constants.<br>';

}

if($extenstion === TRUE && $constants === TRUE){

foreach($constantsArray['libsodium'] as $constant=>$value){

if(preg_match('/CRYPTO_SECRETBOX_NONCEBYTES|CRYPTO_SECRETBOX_KEYBYTES/', $constant)){

echo 'Your predefined constant\'s name is set as this: ' . $constant . ' To use in your functions: random_bytes(' . $constant . ');' . '<br>';

}

}

echo 'Here is a full list of your Libsodium constants:<br>';
print_r(get_defined_constants(true)['libsodium']);

}

//***Leave these commented out when you first run the test.***

//To see ALL of your constants uncomment this line:
//print_r(get_defined_constants(true));

//To see ALL of your extensions uncomment this line:
//print_r(get_loaded_extensions());

echo '</pre>';

关于PHP random_bytes 与钠整数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53956155/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com