[英]How to encrypt/decrypt data in some columns of a table and when a new record gets inserted it should also get encrypt
i know like this to insert a new record 我知道这样插入新记录
INSERT INTO dbo.Customer_data (Customer_id, Customer_Name, Credit_card_number)
VALUES (25665, 'mssqltips4', EncryptByKey( Key_GUID('SymmetricKey1'), CONVERT(varchar,'4545-58478-1245') ) );
but i want to insert a new record with a normal insert statement which should get encrypted. 但是我想用应该被加密的普通插入语句插入一条新记录。 ex:
例如:
INSERT INTO dbo.Customer_data (Customer_id, Customer_Name, Credit_card_number)
VALUES (25665, 'mssqltips4','4545-58478-1245') ) );
Few months ago I had similar situation. 几个月前,我遇到过类似情况。 A table containing personal data need to have some of the columns encrypted, but the table is used in legacy application and have many references.
包含个人数据的表需要对某些列进行加密,但是该表在旧版应用程序中使用并且具有许多引用。
So, I you can create a separate table to hold the encrypted data: 因此,我可以创建一个单独的表来保存加密的数据:
CREATE TABLE [dbo].[Customer_data_encrypted]
(
[customer_id] PRIMARY KEY -- you can create foreign key to the original one, too
,[name] VARBANRY(..)
,[cretit_card_numbe] VARBINARY(..)
);
Then create a INSTEAD OF INSERT UPDATE DELETE
trigger on the original table.The logic in the trigger is simple: 然后在原始表上创建一个
INSTEAD OF INSERT UPDATE DELETE
触发器,触发器中的逻辑很简单:
***
or 43-****-****-****
) ***
或43-****-****-****
) Then, perform a initial migration to move the data from the original table to the new one and then mask it. 然后,执行一次初始迁移,以将数据从原始表移至新表,然后对其进行屏蔽。
Performing the steps above are nice because: 执行上述步骤非常好,因为:
EXECUTE AS OWNER
in order to have access to the symmetric keys and perform changes directly in the T-SQL statement without opening the certificates or by users who have not access to them EXECUTE AS OWNER
创建触发器,以便能够访问对称密钥并直接在T-SQL语句中执行更改,而无需打开证书或无法访问证书的用户 It depends on your environment and business needs because for one of the tables I have stored the encrypted value as new column, not separate table. 这取决于您的环境和业务需求,因为对于其中一个表,我已将加密值存储为新列,而不是单独的表。 So, choose what is more appropriate for you.
因此,选择更适合您的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.