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.

5 – Cell-Level Encryption• Open the HighSymKey1 symmetric key with the MyHighCertcertificate through the OPEN SYMMETRIC KEY method.• Execute the INSERT method while using the EncryptByKey methodto encrypt the value that is passed in the @Identification_Valueargument. This encryption includes the use of the @Borrower_IDargument as the authenticator.• Capture the new Borrower_Identification_ID of the insertedrecord, which is referenced through the use of @@IDENTITY, andreturns it as the result of the stored procedure.• Catch the occurrence of an error so that the stored procedure failsgracefully. This is accomplished by the use of the TRY…CATCHmethod.• Check the HighSymKey1 symmetric key to determine if it is openbefore attempting to close it through the sys.openkeys catalogview. If it is open, the key is closed using the CLOSE SYMMETRICKEY method.Listing 5-17 shows the full code for the stored procedure.USE HomeLending;GOCREATE PROCEDURE dbo.Insert_Borrower_Identification@Borrower_ID bigint,@Identification_Type_ID int,@Identification_Value varchar(250)ASBEGIN TRY-- Opens the symmetric key for useOPEN SYMMETRIC KEY HighSymKey1DECRYPTION BY CERTIFICATE MyHighCert;-- Performs the update of the recordINSERT INTO dbo.Borrower_Identification(Borrower_ID,Identification_Type_ID,Identification_Value_E)VALUES(@Borrower_ID,@Identification_Type_ID,EncryptByKey(Key_GUID('HighSymKey1'),124

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

Saved successfully!

Ooh no, something went wrong!