Solved

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

Posted on 2011-09-22
1
340 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
Comment Utility
--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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
In this article I will describe the Copy Database Wizard 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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

763 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

6 Experts available now in Live!

Get 1:1 Help Now