如何使用php搜索加密的txt文件

问题描述 投票:1回答:1

对于简单的邮件列表,我将数据存储在.txt文件中。在txt文件中有5行。其中2个(包含名称和电子邮件)已加密。为了安全起见,我存储了姓名和电子邮件加密。

这是我搜索文件的方式:

/* EMAIL SEARCH */
$email_search = $_GET['email_search']; // get string from url for search
if (isset($email_search)) {
    $searchthis = strtolower($email_search);    
    $email_matches = array();

    $files = glob("subscribers/*.txt"); // Specify the file directory by extension (.txt)

    foreach($files as $file) { // Loop the files in the directory   {

        $handle = @fopen($file, "r");

        if ($handle) {

            $lines = file($file);           
            $grab_email = strtolower($lines[3]); // for sorting only

            while (!feof($handle)) {
                $buffer = fgets($handle);

                if(strpos(strtolower($buffer), $searchthis) !== FALSE) // strtolower; search word not case sensitive    

                    $email_matches[$file] = $grab_email; // put all lines in array  indexed by email

            }

            fclose($handle);
        }
    }

}
asort($email_matches);



<!-- search form -->
<form class="search-form form-inline" action="admin.php" method="GET">  
    <div class="input-group mb-3">
        <input class="form-control" type="text" name="email_search" placeholder="Search for..." />
        <div class="input-group-append">                
            <button class="btn btn-primary" type="submit">Search</button>
        </div>
    </div>                          
</form>

这是txt文件的外观:

id-5e0786c07c802 // id
Friends //category
ygkKcL/jz9U= // name (encrypted)
6gkKcL/jz9XuVRNayyIVcFbLw3ord0nc7IJj // email (encrypted)
902d95a9bf1c3f59a3996e4e7b4dec79 // token

[之前,当数据未加密时,此搜索工作正常!但是,当每个文件中的名称和电子邮件行都已加密时,我现在如何搜索?

php search encryption
1个回答
0
投票

具有加密值的搜索如何?

在您的代码中,$_GET['email_search']包含您要搜索的单词或值。我不知道您的加密方式如何,但是您可以对要搜索的单词进行加密,例如:

$email_search = openssl_encrypt($_GET['email_search'], $ciphering, $encryption_key, $options, $encryption_iv); // get string from url for search
© www.soinside.com 2019 - 2024. All rights reserved.