gpt4 book ai didi

security - 存储和搜索加密数据字段,例如电子邮件

转载 作者:行者123 更新时间:2023-12-02 19:09:07 32 4
gpt4 key购买 nike

我想知道在数据库中存储电子邮件和电话号码等敏感字段时遵循的最佳实践是什么。假设您想通过电子邮件和电话号码进行搜索,并且该应用程序也会向其用户发送电子邮件和短信。由于此数据很敏感,因此您需要对其进行加密。散列不是一个选项,因为你无法取消它的散列。Rjindael 或 AES 等加密标准使数据安全,但您无法通过它搜索数据库,因为为相同输入生成的加密字符串始终不同。

那么在这种情况下,我是否需要在表中存储哈希值和加密字段?或者是否为此类字段部署了其他强加密技术。

最佳答案

查看CipherSweet 。它是一个许可非常宽松的开源库,在 PHP 中提供可搜索加密。

其实现类似于 Ebbe's answer ,但还有更多警告:

  1. CipherSweet 自动处理 key 分割,through a well-defined protocol .
  2. CipherSweet 支持多种功能盲索引(明文转换的截断哈希)以方便高级搜索。
    • 有关其设计的安全影响的更多信息,请访问 here .

此外,API 相对简单:

<?php
use ParagonIE\CipherSweet\BlindIndex;
use ParagonIE\CipherSweet\CipherSweet;
use ParagonIE\CipherSweet\CompoundIndex;
use ParagonIE\CipherSweet\EncryptedRow;
use ParagonIE\CipherSweet\Transformation\LastFourDigits;

/** @var CipherSweet $engine */
// Define two fields (one text, one boolean) that will be encrypted
$encryptedRow = (new EncryptedRow($engine, 'contacts'))
->addTextField('ssn')
->addBooleanField('hivstatus');

// Add a normal Blind Index on one field:
$encryptedRow->addBlindIndex(
'ssn',
new BlindIndex(
'contact_ssn_last_four',
[new LastFourDigits()],
32 // 32 bits = 4 bytes
)
);

// Create/add a compound blind index on multiple fields:
$encryptedRow->addCompoundIndex(
(
new CompoundIndex(
'contact_ssnlast4_hivstatus',
['ssn', 'hivstatus'],
32, // 32 bits = 4 bytes
true // fast hash
)
)->addTransform('ssn', new LastFourDigits())
);

实例化并配置对象后,您可以像这样插入行:

<?php
/* continuing from previous snippet... */
list($encrypted, $indexes) = $encryptedRow->prepareRowForStorage([
'extraneous' => true,
'ssn' => '123-45-6789',
'hivstatus' => false
]);
$encrypted['contact_ssnlast4_hivstatus'] = $indexes['contact_ssnlast4_hivstatus'];
$dbh->insert('contacts', $encrypted);

然后从数据库检索行就像在 SELECT 查询中使用盲索引一样简单:

<?php
/* continuing from previous snippet... */
$lookup = $encryptedRow->getBlindIndex(
'contact_ssnlast4_hivstatus',
['ssn' => '123-45-6789', 'hivstatus' => true]
);
$results = $dbh->search('contacts', ['contact_ssnlast4_hivstatus' => $lookup]);
foreach ($results as $result) {
$decrypted = $encryptedRow->decrypt($result);
}

CipherSweet 目前在 PHP 中实现和 Node.js ,其他 Java、C#、Rust 和 Python 实现即将推出。

关于security - 存储和搜索加密数据字段,例如电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22337536/

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