17.07.2015 Views

Download eBook (PDF) - Red Gate Software

Download eBook (PDF) - Red Gate Software

Download eBook (PDF) - Red Gate Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

7 – One-Way Encryption)RETURNS varchar(7)WITH ENCRYPTIONASBEGINDECLARE @Rtn varchar(7)IF @Type = 'L01' SET @Rtn = 'HYz5#45';IF @Type = 'L02' SET @Rtn = 'Ku&7723';IF @Type = 'L03' SET @Rtn = 'PW2%230';IF @Type = 'L04' SET @Rtn = 'T^542Xc';IF @Type = 'L05' SET @Rtn = '89*we@4';IF @Type = 'L06' SET @Rtn = '098&tsS';RETURN @Rtn;ENDGOListing 7-1: The GetHashSalt UDF.Inclusion of the WITH ENCRYPTION option prevents the revelation of these saltvalues by viewing the definition of the user defined function, as well aspreventing its modification. This renders the code of the user defined functioninvisible through catalog views, unencrypted backup files and through SSMS.With this user defined function, we can salt our plain text values before theyare encrypted. The process of doing this involves the following steps:• Call the GetHashSalt user defined function and assign it to avariable.• Concatenate the variable to the plain text of the data that is to beencrypted.• Place the resulting concatenated value in the plain text argument of theHashbytes function.For example, an original plain text of "555-37-0143" and a salt value being"HYz5#4555", the resulting concatenated value will be "HYz5#45555-37-0143". Using the "SHA1" algorithm, the resulting salted hash value will be0xD544F25AC44F6CBC108DA211D2A48990A343359C.Listing 7-2 will grant EXECUTE permissions on the GetHashSalt UDF to theSensitive_high and Sensitive_meduim database roles.156

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!