SQLUSA.com
SQL SERVER 2008 GRAND SLAM
FREE TRIAL  CLICK HERE TO ORDER  SEARCH
SQL JOBS SQL Server Training Scripts JOB BANK
  SQL Server 2008 Training Scripts  
  SQL Server 2005 Training Scripts  
News SQL Server Articles SQL Format

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

*/

Order SQL 2008 GRAND SLAM Today!
SQLUSA.com Home Page
SQL Server Training at www.sqlusa.com.
SQL Server 2008 Video Training at www.sqlusa.com.
SQL Server 2005 Training Videos at www.sqlusa.com.
Microsoft SQL Server 2000 Training Videos at www.sqlusa.com.

FREE SQL & Business Intelligence / OLAP Short Videos on YOUTUBE.com

Microsoft Community Contributor 2011
Invest in Your SUCCESS!

Search SQLUSA FREE SQL Server Articles & FREE T-SQL Scripts


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

SQL Server 2012 is a program product of Microsoft Corporation.
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.