1. <small id='tcA1P'></small><noframes id='tcA1P'>

        • <bdo id='tcA1P'></bdo><ul id='tcA1P'></ul>
        <tfoot id='tcA1P'></tfoot>

        <i id='tcA1P'><tr id='tcA1P'><dt id='tcA1P'><q id='tcA1P'><span id='tcA1P'><b id='tcA1P'><form id='tcA1P'><ins id='tcA1P'></ins><ul id='tcA1P'></ul><sub id='tcA1P'></sub></form><legend id='tcA1P'></legend><bdo id='tcA1P'><pre id='tcA1P'><center id='tcA1P'></center></pre></bdo></b><th id='tcA1P'></th></span></q></dt></tr></i><div id='tcA1P'><tfoot id='tcA1P'></tfoot><dl id='tcA1P'><fieldset id='tcA1P'></fieldset></dl></div>
        <legend id='tcA1P'><style id='tcA1P'><dir id='tcA1P'><q id='tcA1P'></q></dir></style></legend>

        如何加密 MySQL 表中的特定列?

        时间:2023-10-26
        • <bdo id='wK0Yn'></bdo><ul id='wK0Yn'></ul>
          <tfoot id='wK0Yn'></tfoot>
          <legend id='wK0Yn'><style id='wK0Yn'><dir id='wK0Yn'><q id='wK0Yn'></q></dir></style></legend>
              <tbody id='wK0Yn'></tbody>

              <i id='wK0Yn'><tr id='wK0Yn'><dt id='wK0Yn'><q id='wK0Yn'><span id='wK0Yn'><b id='wK0Yn'><form id='wK0Yn'><ins id='wK0Yn'></ins><ul id='wK0Yn'></ul><sub id='wK0Yn'></sub></form><legend id='wK0Yn'></legend><bdo id='wK0Yn'><pre id='wK0Yn'><center id='wK0Yn'></center></pre></bdo></b><th id='wK0Yn'></th></span></q></dt></tr></i><div id='wK0Yn'><tfoot id='wK0Yn'></tfoot><dl id='wK0Yn'><fieldset id='wK0Yn'></fieldset></dl></div>

                  <small id='wK0Yn'></small><noframes id='wK0Yn'>

                  本文介绍了如何加密 MySQL 表中的特定列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试创建一个简单的消息系统 (PHP) 页面,该页面使用 MySQL 表来存储条目.我将在表格中使用的列的粗略轮廓是:

                  I am experimenting with creating a simple message system (PHP) page that uses a MySQL table to store the entries. The rough outline of the columns I'll use in the table are:

                  msg_id(主键,auto_increment)

                  msg_id (primary key, auto_increment)

                  user_id(指向创建消息的用户的外键)

                  user_id (foreign key pointing to the user who created the message)

                  time(提供 msg 时间戳的 DATETIME 条目)

                  time (a DATETIME entry to provide msg timestamps)

                  msg(包含 msg 的 VARCHAR)

                  msg (a VARCHAR containing the msg)

                  accessable(只是一个 int(1),0 表示除了用户自己之外没有人可以读取 msg,1 表示其他人可以读取它)

                  accessable (just an int(1), 0 means no one except the user himself can read the msg, and 1 means others can read it)

                  我想知道的是,加密 msg 字段以便窥探者无法读取它的最佳方法是什么(比方说,通过打开 mysql CLI 或 phpMyAdmin 并只读取值连续存储)?

                  What I'm wondering is, what's the best way to encrypt the msg field so prying eyes can't read it (let's say, by opening the mysql CLI or phpMyAdmin and just read the value stored in a row)?

                  如果accessable"设置为0,那么只有他/她自己的用户应该能够阅读它(通过访问某个PHP页面),但如果设置为1,其他人也应该能够阅读它.我不知道如何解决这个问题,所以非常感谢您的帮助!

                  If "accessable" is set to 0, then only the user him/herself should be able to read it (by accessing some PHP page), but if set to 1, everyone else should be able to read it as well. I don't know how to tackle this, so any help is very appreciated!

                  推荐答案

                  在此处查看可能的加密功能列表:

                  Look here for list of possible encryption functions:

                  http://dev.mysql.com/doc/refman/5.1/en/encryption-functions.html

                  您可以为更新创建触发器并检查那里的字段accessable.类似的东西:

                  You can create trigger for update and check there field accessable. Something like that:

                  CREATE TRIGGER crypt_trg BEFORE UPDATE ON table FOR EACH ROW
                  BEGIN
                    IF new.accessable = 0 THEN
                      SET new.msg := ENCRYPT(new.msg, 'key');
                    ELSE
                      SET new.msg := DECRYPT(new.msg, 'key');
                    END IF;
                  END;
                  

                  您还可以使用此查询更新表中的所有现有记录:

                  You also can update all existing records in you table with this query:

                  UPDATE table SET msg = IF(accessable = 0, ENCRYPT(msg, 'key'), DECRYPT(msg, 'key'));
                  

                  所以你可以为你的 PHP 代码选择记录:

                  So you can select records for you PHP code:

                  SELECT msg_id, user_id, time, IF(accessable = 0, DECRYPT(msg, 'key'), msg) msg
                  FROM table
                  

                  UPD.这里也有类似的问题:

                  MySQL 加密列

                  这篇关于如何加密 MySQL 表中的特定列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 MySQL 的 `encrypt` 函数中使用 `bcrypt` 算法来验证密码? 下一篇:C# 从 SQL Server EncryptByPassPhrase 解密字节?

                  相关文章

                  • <bdo id='nhBlP'></bdo><ul id='nhBlP'></ul>

                  <small id='nhBlP'></small><noframes id='nhBlP'>

                    <tfoot id='nhBlP'></tfoot>
                  1. <i id='nhBlP'><tr id='nhBlP'><dt id='nhBlP'><q id='nhBlP'><span id='nhBlP'><b id='nhBlP'><form id='nhBlP'><ins id='nhBlP'></ins><ul id='nhBlP'></ul><sub id='nhBlP'></sub></form><legend id='nhBlP'></legend><bdo id='nhBlP'><pre id='nhBlP'><center id='nhBlP'></center></pre></bdo></b><th id='nhBlP'></th></span></q></dt></tr></i><div id='nhBlP'><tfoot id='nhBlP'></tfoot><dl id='nhBlP'><fieldset id='nhBlP'></fieldset></dl></div>
                    <legend id='nhBlP'><style id='nhBlP'><dir id='nhBlP'><q id='nhBlP'></q></dir></style></legend>