Solved

MS SQL 2008 R2, Table Filed Value --> Encryption & Decryption

Posted on 2011-09-22
1
343 Views
Last Modified: 2012-05-12
SQLQuery17.sql

Hi,

      Our requirement: We need to encrypt the table records (i.e.) field values using 3DES algorithm.

       For that, we got the attached code from MSDN site and working fine. But we have the following 2 questions.

Question 1: If we BACKUP & RESTORE the same database, the decryption is not working for old / existing records. But the new records (i.e. records created after restore) are working fine. But we need to decrypt the old records also. --- HOW?

Question 2: Suppose the master database or master key DAMAGED / LOST, how can we get the same key and decryption for old recods.... HOW?

We need solution for these 2 questions.

If you have any other better logic for encryption / decryption other than the attached code, please let us know, we will follow that logic.

We are developing code in ASP.NET C#3.5 & MS SQL 2008 R2
0
Comment
1 Comment
 
LVL 5

Accepted Solution

by:
Eduardo Goicovich earned 250 total points
ID: 36580883
--1 backup certificate and private key

USE master
GO
BACKUP CERTIFICATE TestSRSPwd
TO FILE = ‘C:\TestSRSPwd.cer’
WITH PRIVATE KEY (FILE = ‘C:\TestSRSPwd.pvk’ ,
ENCRYPTION BY PASSWORD = ‘mY_P@$$w0rd’ )
GO

--2 restore
--2.1 recreate previous key
USE master
GO

CREATE MASTER KEY ENCRYPTION BY PASSWORD = ‘23987hxJKL969#ghf0%94467GRkjg5k3fd117r$$#1946kcj$n44nhdlj’
GO

--2.2 restore certificate and private key
CREATE CERTIFICATE TestSRSPwd
FROM FILE = ‘C:\TestSRSPwd.cer’
WITH PRIVATE KEY (FILE = ‘C:\TestSRSPwd.pvk’,
DECRYPTION BY PASSWORD = ‘mY_P@$$w0rd’);
GO
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now