如何在mysql数据库中加密电子邮件但仍能查询? [英] how to encrypt emails in mysql database but still be able to query them?

查看:195
本文介绍了如何在mysql数据库中加密电子邮件但仍能查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用加密将用户的电子邮件地址存储在MySQL数据库中,以确保数据库受损时不会被公开。我相信如果我使用mysql的 AES_ENCRYPT() 功能我不能在 INNODB 表中创建索引,因为我必须使用 BLOB 数据类型。如果表格变得非常大选择将需要很长时间。

I want to store the email addresses of users in a MySQL database using encryption to ensure that they won't be made public if the database gets compromised. I believe if I encrypt them with mysql's AES_ENCRYPT() function I can not create an index in an INNODB table because I have to use a BLOB datatype. If the table gets very large selects it will take a long time.

什么是保护电子邮件地址的最佳解决方案,但仍然能够快速查询它们并将其保留为

What is the best solution for securing email address but still being able to query them fast and preserve them as unique values in the column?

推荐答案

当用户在您的网站上注册时,请使用AES_ENCRYPT()加密电子邮件。 INSERT到用户(电子邮件)VALUES(AES_ENCRYPT(someemail@example.com','aeskey'));

When a user registers on your site, use AES_ENCRYPT() to encrypt the email.

INSERT into users (email) VALUES (AES_ENCRYPT('someemail@example.com', 'aeskey'));

当您查询数据库时,可以像这样调用AES_DECRYPT()函数:

When you query your database, you can call the AES_DECRYPT() function like this:

SELECT AES_DECRYPT(email, 'aeskey') from users;

这篇关于如何在mysql数据库中加密电子邮件但仍能查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆