<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'SQL Server 2008', 'T-SQL', and 'encryption'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=SQL+Server+2008,T-SQL,encryption&amp;orTags=0</link><description>Search results matching tags 'SQL Server 2008', 'T-SQL', and 'encryption'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>&amp;quot;Cloning&amp;quot; Symmetric Keys</title><link>http://sqlblog.com/blogs/michael_coles/archive/2009/06/17/cloning-symmetric-keys.aspx</link><pubDate>Thu, 18 Jun 2009 01:40:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14741</guid><dc:creator>Mike C</dc:creator><description>&lt;P&gt;It's well-known by now that SQL Server 2005 and 2008 include new encryption-related statements that allow you to create and administer encryption keys. You can use &lt;FONT face=courier&gt;CREATE CERTIFICATE&lt;/FONT&gt; to create or&amp;nbsp;import a certificate or &lt;FONT face=courier&gt;DROP ASYMMETRIC KEY&lt;/FONT&gt; to remove an asymmetric key from the database, for instance.&amp;nbsp; One of the interesting ommissions from the T-SQL encryption statements is the statements necessary to backup and restore a symmetric key.&amp;nbsp; Why would you want to do this?&amp;nbsp; I can think of a couple of reasons off the top of my head:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;You need to backup symmetric keys (and all other encryption keys, in fact) as part of an overall disaster recovery (DR) program.&amp;nbsp; If a server needs to be rebuilt you obviously need a way to restore all encryption keys.&lt;/LI&gt;
&lt;LI&gt;You need to implement the same symmetric keys on multiple servers.&amp;nbsp; There could be a couple of reasons for this -- you might encrypt data on one server and decrypt it on another, or you might be load-balancing across a server farm and need identical encryption keys on multiple servers simultaneously.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;It seems like a bit of an oversight to not include &lt;FONT face=courier&gt;BACKUP&lt;/FONT&gt; and &lt;FONT face=courier&gt;RESTORE SYMMETRIC KEY&lt;/FONT&gt; options in T-SQL, but in practice you can effectively achieve the same end results with the standard &lt;FONT face=courier&gt;CREATE SYMMETRIC KEY&lt;/FONT&gt; statement.&amp;nbsp; Basically the &lt;FONT face=courier&gt;CREATE SYMMETRIC KEY&lt;/FONT&gt; statement gives you an option to "clone" the exact same symmetric key on any SQL Server 2005 or 2008 instance, anywhere, at any time.&amp;nbsp; To create a cloneable symmetric key you need to specify two special &lt;FONT face=courier&gt;CREATE SYMMETRIC KEY&lt;/FONT&gt; options:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The &lt;FONT face=courier&gt;IDENTITY_VALUE&lt;/FONT&gt; option, which SQL Server uses to generate a GUID (uniqueidentifier) for the key&lt;/LI&gt;
&lt;LI&gt;The &lt;FONT face=courier&gt;KEY_SOURCE&lt;/FONT&gt; option, which SQL Server uses as key material to generate the actual key&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;As long as you specify the same values for the &lt;FONT face=courier&gt;IDENTITY_VALUE&lt;/FONT&gt; and &lt;FONT face=courier&gt;KEY_SOURCE&lt;/FONT&gt; options (and the same &lt;FONT face=courier&gt;ALGORITHM&lt;/FONT&gt;), your symmetric key will be exactly the same no matter where, when, or how many times&amp;nbsp;you create it.&amp;nbsp; To be honest, if I were creating a list, always use &lt;FONT face=courier&gt;IDENTITY_VALUE&lt;/FONT&gt; and &lt;FONT face=courier&gt;KEY_SOURCE&lt;/FONT&gt; would be listed in the top 10 list of SQL Server encryption best practices.&lt;/P&gt;
&lt;P&gt;Here's a quick sample demonstrating the &lt;FONT face=courier&gt;CREATE SYMMETRIC KEY&lt;/FONT&gt; statement with &lt;FONT face=courier&gt;IDENTITY_VALUE&lt;/FONT&gt; and &lt;FONT face=courier&gt;KEY_SOURCE&lt;/FONT&gt; specified:&lt;/P&gt;
&lt;P&gt;&lt;FONT face=courier&gt;CREATE SYMMETRIC KEY test_aes128_key&lt;BR&gt;WITH KEY_SOURCE = 'I am the very model of a modern major general',&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IDENTITY_VALUE = 'E pluribus unum',&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ALGORITHM = AES_128&lt;BR&gt;ENCRYPTION BY PASSWORD = &lt;A href="mailto:'p@$$w0rd'"&gt;'p@$$w0rd'&lt;/A&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This &lt;FONT face=courier&gt;CREATE SYMMETRIC KEY&lt;/FONT&gt; statement will create the same symmetric encryption key on any SQL Server 2005 or 2008 instance on which you run it.&amp;nbsp; This brings up another point, about security.&amp;nbsp; If the same &lt;FONT face=courier&gt;KEY_SOURCE&lt;/FONT&gt; and &lt;FONT face=courier&gt;IDENTITY_VALUE&lt;/FONT&gt; options can create the exact same encryption key on any of your servers, they will create the exact same encryption key on any of my servers, or any server owned by any hacker anywhere in the world.&amp;nbsp; So once you've run your &lt;FONT face=courier&gt;CREATE SYMMETRIC KEY&lt;/FONT&gt; statement, the &lt;FONT face=courier&gt;IDENTITY_VALUE&lt;/FONT&gt; and &lt;FONT face=courier&gt;KEY_SOURCE&lt;/FONT&gt; need to be handled like any other secure information.&amp;nbsp; Don't leave them lying around where just anyone can access them.&amp;nbsp; Store them with your certificates, key backups, and other confidential materials in a secure off-site location.&lt;/P&gt;
&lt;P&gt;So what happens when you don't specify the &lt;FONT face=courier&gt;IDENTITY_VALUE&lt;/FONT&gt; and &lt;FONT face=courier&gt;KEY_SOURCE&lt;/FONT&gt; options?&amp;nbsp; Well, basically SQL Server generates an unpredictable GUID to identify the symmetric key and the encryption key source material is randomly generated.&amp;nbsp; Basically you'll never regenerate the exact same key again.&amp;nbsp; Ever.&amp;nbsp; There could be situations where this would be handy.&amp;nbsp; The concept of "session keys" comes to mind.&amp;nbsp; A session key is basically a "temporary" key that's only required to encrypt data for a user during a single session.&amp;nbsp; Since it only exists for the life of the session, a totally randomly-generated key is just fine.&lt;/P&gt;
&lt;P&gt;For my tastes, it would make more sense to require &lt;FONT face=courier&gt;IDENTITY_VALUE&lt;/FONT&gt; and &lt;FONT face=courier&gt;KEY_SOURCE&lt;/FONT&gt; options by default. If you didn't want to specify both of these options there should be another option/indicator specifically to say that you want these options generated randomly.&amp;nbsp; At any rate, it's a good idea to get into the habit of treating these options as if they are mandatory unless they have a very specific special-purpose requirement (e.g., "session keys").&lt;/P&gt;</description></item></channel></rss>