我是php和stackoverflow的新手,因此可能会出现一些错误。如果有,请通知我,我会尽快解决。
我的加密函数:
function encrypt($data){
$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
$ciphertext = sodium_crypto_secretbox($data, $nonce, $GLOBALS['key']);
$ciphertext = base64_encode($ciphertext);
$ciphertext .= "[-SPLIT-]" . base64_encode($nonce);
return $ciphertext;}我的解密函数:
function decrypt($data){
$data = explode("[-SPLIT-]", $data);
$ciphertext = base64_decode($data[0]);
$nonce = base64_decode($data[1]);
$plaintext = sodium_crypto_secretbox_open($ciphertext, $nonce, $GLOBALS['key']);
if(!$plaintext){$plaintext = "FAILED";}
return $plaintext;}我已经做了足够的测试,知道我正在将从encrypt函数返回的$ciphertext传递给decrypt函数。
如何让函数返回在我的encrypt函数中加密的解密字符串?
发布于 2021-03-13 13:58:09
发现了我的问题,一个简单的print_r()把我搞得一团糟。上面的代码可以正常工作,我将很快发布一些改进。
https://stackoverflow.com/questions/66523551
复制相似问题