数据库加密:MSSQL 2008+数据库加密并在Coldfusion中使用

时间:2015-12-08 16:51:24

标签: sql-server database csv encryption coldfusion

我们的客户发送该文件的CSV文件(平均30万条记录)。我们在 Microsoft SQL 数据库中导入。

从CSV文件导入数据时有没有办法,我可以加密(SHA& Other)??如何向数据库发送查询(选择,插入和更新)?来自 coldfusion Microsoft SQL

Application Server:Coldfusion 9,9+和Lucee 数据库:Microsoft SQL Server 2008 +

例如我已经在mysql中使用了。我在MSSQL看起来一样:

MYSQL示例

INSERT:

INSERT INTO List_encrypted 
(fname,Lname,email) 
Values
(AES_ENCRYPT(fname,'dbkey'),
AES_ENCRYPT(Lname,'dbkey'), 
AES_ENCRYPT(email,'dbkey')) 
from List_encrypted

选择

select CAST(AES_DECRYPT(fname,'dbkey')AS CHAR (50)) AS FirstName, 
CAST(AES_DECRYPT(Lname,'dbkey')AS CHAR (50)) AS LastName, 
CAST(AES_DECRYPT(email,'dbkey')AS CHAR (50)) AS email 
from List_encrypted

MYSQL导入CSV数据

LOAD DATA LOCAL INFILE  'C:\filename.txt'
INTO TABLE List_encrypted
CHARACTER SET utf8
FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES
(fname,lname,email,stamp_dt)
SET 
fname = AES_ENCRYPT(@fname,'dbkey'),
lname = AES_ENCRYPT(@lname,'dbkey'),
email  = AES_ENCRYPT(@email,'dbkey'),
stamp_dt        = now();

这就是我在MSSQL中所做的: 我不知道如何加密,导入

CREATE TABLE List_encrypted
(
 ID int not null identity(1, 1) primary key,
 LName varchar(255),
 FName varchar(255),
 email varchar(255),
);

BULK INSERT [List_encrypted]
FROM 'C:\filename.txt'
WITH 
(
  FIELDTERMINATOR = '" ; "',
  ROWTERMINATOR = '\r\n'
)

1 个答案:

答案 0 :(得分:1)

只有一种方法可以在临时表和物理表中批量导入。

示例:创建表

CREATE TABLE #t1
(
    NAME varchar(255)
);

在临时表中导入

BULK INSERT [#t1]
FROM 'C:\CSV\names.txt'
WITH 
(
FIELDTERMINATOR = '" | "',
ROWTERMINATOR   = '\n'
)

在物理表中导入& ENCRYPT

select 
   CAST(DECRYPTBYPASSPHRASE('dbkey',Encrypted) AS varchar(8000)) 
   AS Encrypted 
from t1