Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-22
1
Medium Priority
?
355 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 1000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
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.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

972 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