SQL Server 2008 Encryption Guide
SQL Server 2008 Encryption Guide
tosiccaosin
w
Ish
,liowyouanencrypoitnanddecrypoitnaglorh
timniSQLServer2008.
[Link]
new
.qyauertiveg2ianS
v0oderpq8noltnyedou,tsrFi-1.
eablt testandabesdataeC
-eatr2.
Ascanbeseenintheusertableth,epasswordisavarbinaryof500a,ndthereasonswhywhenthe
ereatgrsioniyenpcrthetbyedw
psgatenhrdorthattdavoihdsoultiandsmerahctesm
arntygenrgioraloniyT enpcrthe
delifhetnipsacewhat
eToeathnF
O
criu-nT
hctm
[Link]
A
iygnpocrtl
varavesecirtihattedatapecirbecanthim tgio,ralhetofniunfcthetnI
oofuevlaheteortsotezisgrealahw teibalivrahnareoteradlcehntnadm ,slla
[Link]
orfkeyaam ,psare2etvseciw
rchohni,iyenpcrtow
rS
fvQ
edroesrLauesoniyenpcrt
w hsepydantyorepctnrec
ENCRYPTBYPASSPHRASEk)('e@
H
ly,'ialc
belw lihtaw
tdaorsi kye'het' htatocuantontikaetesapl
netgotorf
eToeathnFOcriu-nT cthf4m
.oeD
ntA
iygpoecrtl
Hehtrevesrpeorceosenfcyrpoidtsniohntaerl,adyencyrpetdpaswodrhotcefoulmnpoasibsantied.
yenpcrtowvtedresorSQ
verhansoL
thwtedyenpicrtsiandeablivarzeisgearlhetofam pareet
DECRYPTBYPASSPHRASEk('e)@ vay,' lc
w
psahdeortandeyenpcrtsi tw ihcw khteyiheit ueds,beotw am
pstareoestrequriosalhatt
deyptnrec
Next, it will be shown how it will be.
'dbo.'xifeprhethw toniiuntcfhet llaw ckeshit
oyptrcninessam
sepltceleunsnangdoi
Now
otsh,owhtepaswodro,hteoflwnig
SUMMARIZEHEREEVERYTHINGWEWRITESTEPBYSTEPTODOTHEEXERCISE
create database prueba1;
use test1
create table user
(
user_id int primary key,
user varchar(20) not null,
pass varbinary(500) not null
)
go
create function FU_ENCRYPT_PASS
(
@key varchar(50)
)
RETURNS VarBinary(500)
AS
BEGIN
DECLARE @pass AS VarBinary(500)
SET @pass = ENCRYPTBYPASSPHRASE('key', @key)
--encrypt the key to encrypt the field.
RETURN @pass
END
create function FU_DESENCRIPTA_PASS
(
@clave VARBINARY(500)
)
RETURNS VARCHAR(50)
AS
BEGIN
DECLARE @pass AS VARCHAR(50)
SET @pass = DECRYPTBYPASSPHRASE('key', @clave)
RETURN @pass
END
insert into user values(1,'user 1', dbo.ENCRYPT_PASS('1234'))
select * from user
go
select id_usuario, usuario, dbo.FU_DESENCRIPTA_PASS(pass) from usuario