我有要更改的视图。但是我想在视图内部使用对称密钥。下面是我的代码:
create view dbo.[Test_view]
select
t.med_id,
t.medicine_name,
case when
t.taxo_id like '%include%' then '1'
else '0' end as 'Taxo_number' ----The taxo_id is encrypted column
from dbo.Meds t
我想在“ Taxo_number”视图中再添加一列,该视图基于使用对称密钥加密的taxo_id列。
My key is: OPEN SYMMETRIC KEY [Test_Key] DECRYPTION BY CERTIFICATE [Test_Cert]
是否可以在“查看”脚本中包含此密钥?请帮助!
答案 0 :(得分:1)
您肯定可以。这是一个POC:
use tempdb;
go
create symmetric key [mykey]
WITH ALGORITHM = AES_256
ENCRYPTION BY PASSWORD = 'SouperSecretz>789'
go
create table dbo.Secrets (
Secret varbinary(400)
)
go
create view dbo.openSecrets
as
select cast(decryptbykey(Secret) as varchar(200)) as OpenSecret
from dbo.Secrets
go
open symmetric key [mykey]
DECRYPTION BY PASSWORD = 'SouperSecretz>789'
go
insert into dbo.Secrets (Secret)
values (ENCRYPTBYKEY(KEY_GUID('myKey'), 'asdfasdf'));
select *
from dbo.openSecrets;
close symmetric key [mykey];
select *
from dbo.openSecrets;
在此演示中,我正在创建:
我针对视图执行的两个选择中,一个选择打开了键,另一个选择没有打开。前者显示明文,而后者返回null
。
因此,只要您在会话中打开密钥,就应该能够看到纯文本数据。如果没有,您将(成功)获得该列的null
。