首页 > 解决方案 > PHP加密,加密时考虑空行

问题描述

我正在使用一些 c# 代码访问的 PHP 中的一些加密,

当我对以下内容进行 sha1 加密时test1:test1:apple,每个在线生成器都会返回:8ee27a0e9368d2835b3fdeb4b50caf1d8f790314 但是,当我运行我的 PHP 脚本时,它会返回296b39344a6eb9d88c3bb1122f5941f0bcf3b0c2test1:test1:apple因为本质上它是在我正在加密的字符串 ( ) 中添加一个空行。

有谁知道如何解决这个问题?这不一定是世界上最糟糕的事情,它只是非常烦人。

我使用的代码非常简单:

function GetRandomWord()
{
$file = "../Core/nouns0.txt";
$file_arr = file($file);
$num_lines = count($file_arr);
$last_index = $num_lines -1;

$rand_index = rand(0, $last_index);
$rand_text = $file_arr[$rand_index];

return $rand_text;
}

$enc = GetRandomWord();
$encrypted = sha1("$username:$password:$enc");
echo $encrypted;

它被脚本捕获在 c# 中。

提前致谢!

标签: php

解决方案


@IłyaBursov 他们的回答有帮助!我将 GetRandomWord() 函数的 return 语句更改为 return trim($rand_text);

谢谢!


推荐阅读