
{"id":7293,"date":"2021-11-30T08:29:23","date_gmt":"2021-11-30T08:29:23","guid":{"rendered":"https:\/\/rax-stg-wp-aws.com\/blogs\/mssql-server-migrate-database-with-cle-cell-level-encryption\/"},"modified":"2026-11-03T19:28:25","modified_gmt":"2026-11-03T19:28:25","slug":"mssql-server-migrate-database-with-cle-cell-level-encryption","status":"publish","type":"blogs","link":"https:\/\/www.rackspace.com\/en-gb\/blogs\/mssql-server-migrate-database-with-cle-cell-level-encryption\/","title":{"rendered":"MsSQL Server \u2013 Migrate Database with CLE (Cell Level Encryption)"},"content":{"rendered":"<p>Data security is one of the critical aspects of database management. When we are encrypting sensitive data, there are many ways to achieve this in MS SQL Server like CLE, TDE, and Always Encrypted. When you are encrypting data within the cell using a certificate or keys, this is known as CLE (Cell Level Encryption).&nbsp;&nbsp;In this blog, I have discussed the necessary steps for restoring a database and retrieving encrypted data when CLE (Cell Level Encryption) is implemented.<\/p>\n<p><strong>&nbsp;Problem:&nbsp;<\/strong><\/p>\n<p>1. ERROR: One of the issues you may see is an application or some of the TSQL code which is decrypting the data starts giving the following error.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26386-body-Picture1_11.png\" alt=\"MSSQL PIC !\" \/><\/p>\n<p>2. DecryptByKey function is not able to decrypt the data. This will not give you any error however functionality will be impacted due to missing encryption keys.&nbsp;&nbsp;<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26386-body-Picture2_14.png\" alt=\"MSSQL PIC 2\" \/><\/p>\n<p><strong>Solutions<\/strong><\/p>\n<p>As we did not open the database master key decryption of data is not possible, also DMK is not encrypted by the current instance service master key hence you see such an issue, we have many solutions to resolve this, so let\u2019s talk about them one by one<\/p>\n<p><strong>Case 1: When database master key encryption password is known.<\/strong><\/p>\n<p>Step 1: &nbsp;Open the database master key using a password and decrypt the data.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26386-body-Picture3_9.png\" alt=\"MSSQL PIC 3\" \/><\/p>\n<p>Step 2: One of the questions that comes to mind is the possibility of opening the key with a password in every session or if you can hardcode this. The answer is no, in such cases, you will re-encrypt the database master key with the current instance service master key and run the following commands as shown in the snapshot.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26386-body-Picture4_8.png\" alt=\"MSSQL PIC 4\" \/><\/p>\n<p>Step 3: Check if you can decrypt the data without opening the key with a password and the answer is yes because the key is now also encrypted by the current service master key.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26386-body-Picture5_7.png\" alt=\"MSSQL PIC 5\" \/><\/p>\n<p>Step 4: If you want to change the database master key encryption password you need to complete the following step<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26386-body-Picture6_4.png\" alt=\"MSSQL PIC 6\" \/><\/p>\n<p><strong>Case 2: When the database master key encryption password is unknown.<\/strong><\/p>\n<p>In case you are not aware the password and source are accessible. Just use step 4 from case 1 to change the password and follow the procedure in step 1. Else use the following steps as an alternative. This is only possible when the instance where the database is getting restored is not using any other key as the step involved here is restoring the instance service master key.<\/p>\n<p><strong>Example: How to take a backup of instance service master key.&nbsp;<\/strong><\/p>\n<p>&#8212; Take the backup of the service master key&nbsp;<br \/>\nBACKUP SERVICE MASTER KEY TO FILE = &#8216;C:\\Shared\\service_master_key.key<br \/>\nENCRYPTION BY PASSWORD = &#8216;key_P@ssw0rdGqw0956565<\/p>\n<p>\n<strong>Note: <\/strong>Key backup files are very sensitive from a security perspective hence add an SQL service account in the security tab to ensure the SQL server has access to the file, or else you may get the following error during the restoring process.<\/p>\n<p>\n<em>`Msg 15317, Level 16, State 2, Line 53`<br \/>\n`The master key file does not exist or has an invalid format`<\/em><\/p>\n<p>Step 1: Restore the service master key before restoring the database.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26386-body-Picture7_2.png\" alt=\"MSSQL pic 7\" \/><\/p>\n<p>Step 2: &nbsp;Restore the database.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26386-body-Picture8_1.png\" alt=\"MSSQL PIC 8\" \/><\/p>\n<p>Step 3: &nbsp;Check if you can decrypt the data without opening the key with the password and the answer is yes because the key is using the same service master key as we restore both instance service key and database encrypted by it.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26386-body-Picture9_2.png\" alt=\"MSSQL PIC 9\" \/><\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>Each object in MS SQL Server that is used for encryption is secure by Instance-level Service master keys. For managing encryption, it is important to understand that objects involved in encryption are further encrypted by passwords, Keys or certificates.&nbsp;Every time we are migrating a database with cell-level data encryption, we need to either decrypt the key and re-encrypt it with the destination instance service master key or restore the source instance master key.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MsSQL Server \u2013 Migrate Database with CLE (Cell Level Encryption)<\/p>\n","protected":false},"author":2,"featured_media":7295,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","format":"standard","meta":{"content-type":"","nid":"26386","content_type":"blog","created_by":"10130","authored_on":"2023-12-18T08:29:23+00:00","field_article_industries":"","tag_category":"Technical","field_blog_author_text":"by Varun Jha, Manager \u2013 Cloud Database Services Delivery, Rackspace Technology","seo_description":"Deferred Cost of Goods Sold (DCOGS) functionality in Oracle Cost Management. Synchronize revenue and COGS.\r\n","field_featured_image":"","insights_image":"\/wp-content\/uploads\/2026\/blog_technical_images\/26386-insights_image-oracle-technical-blog-1-insights.jpg","field_partners":"","rxt_platforms":"Oracle, Microsoft SQL","product":"","publisheddate":"2021-11-30T08:29:23","rxt_solutions":"Databases, Data Modernization","opengraph_tag":"","x_tag":"","teaser_flag":"Technical Blog","seo_titile":"Migrate Database with CLE in MsSQL SERVER | Rackspace ","field_topics":"","field_slug":"mssql-server-migrate-database-with-cell-level-encryption","footnotes":""},"categories":[178],"tags":[204],"class_list":["post-7293","blogs","type-blogs","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-technical"],"_links":{"self":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/7293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs"}],"about":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/types\/blogs"}],"author":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/comments?post=7293"}],"version-history":[{"count":2,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/7293\/revisions"}],"predecessor-version":[{"id":9352,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/7293\/revisions\/9352"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/media\/7295"}],"wp:attachment":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/media?parent=7293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/categories?post=7293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/tags?post=7293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}