use hello
if not exists(select * from sys.symmetric_keys where name='##MS_DATABASEMASTERKEY##')
create master key
encryption by password='Annai1!'
go
select * from sys.certificates
if not exists(select * from sys.certificates where name='cert246')
create certificate cert246
with subject='certi for sam'
go
create symmetric key sym246
with algorithm=AES_256
encryption by certificate cert246
go
create table sam
(
name varchar(20),
ssn varbinary(256)
)
go
create view sam_decry
as
select name,
convert(nvarchar,DecryptByKey(ssn)) as "ssn"
from sam
go
create trigger trig246
on sam_decry
instead of insert
as
begin
open symmetric key sym246
decryption by certificate cert246;
insert into sam(name,ssn)
select
i.name,
EncryptByKey(Key_GUID('sym246'),ssn)from inserted i
end
-----------------\\
insert into sam_decry
values('sudan','madhuxyu')
select * from sam
select * from sam_decry
Sunday, August 15, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment