SQLUSA
BI TRIO 2008
FREE TRIAL
CLICK HERE TO ORDER

SQL Server 2008 Best Practices
SQL Server 2005 Best Practices

How to apply varbinary(max) in encryption?

Execute the following Microsoft SQL Server Transact-SQL script in Management Studio Query Editor to demonstrate the use of varbinary(max) in data encryption.

USE AdventureWorks

-- SQL Server varbinary(max) - varbinary max

-- SQL Server encryption - SQL Server decryption

CREATE CERTIFICATE CertificateZ

ENCRYPTION BY PASSWORD = '007$$$A'

WITH SUBJECT ='CertificateZ',

START_DATE = '2005/01/01',

EXPIRY_DATE = '2010/01/01'

 

DECLARE  @CypherText VARBINARY(MAX)

 

SET @CypherText = EncryptByCert(Cert_ID('CertificateZ'),'SQLUSA')

 

SELECT Cypher = @CypherText,

       Decyphered = convert(VARCHAR,DecryptByCert(Cert_ID('CertificateZ'),

@CypherText,N'007$$$A'))

 

/* Results

 

Cypher      Decyphered

0xE5E047D77789F08603FD487C0C8AECEA65996540552980AD48D2B2C9C04093C3964B967A

FBD3AB60A13688F8E4E7AB1EF0EE6A9243C597CED181FC1AC2DAA6FA976DEF11453BEE02BE

FAC6E49F60396165DA86A55BDA4AF5A77918818EF10EFB5F64EED358EF6DEBD2438E778677

097DF2C8CFE1D4837EAB4124F66ED966AF75      SQLUSA

*/

The World Leader in SQL Server 2008 Training
The future is just a CLICK away. Your future!
 
SQLUSA.com Home Page

Copyright 2005-2010, SMI Corp. All Rights Reserved.

SQL Server 2008 is a program product of Microsoft Corporation.
SQL Server 2005 is a program product of Microsoft Corporation.
SQL Server 2000 is a program product of Microsoft Corporation.