Mark
Thanx for your response. So if I accidentally delete certificate and then restore certificate by pointing it to this file will above code be still able to decrypt encrypted data?
Main Topics
Browse All TopicsQuestion I have relates to encryption and decryption of data using Certificates in Sql Server 2005 and how do I recover encrypted data back if I drop this certificate accidentally? Or is this even possible? First I drop already existing certificate and then I tried recreating new certificate where it generates new certificate id and later tried to decrypt encrypted data with new certificate but with no success. Is this even possible? If not then should we rely on certificates that can so easily be dropped. What is the best approach? How can I retrieve encrypted data that was once encrypted using old certificate key.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
It's erroring out both on server box and also on my machine:
BACKUP CERTIFICATE WebSitePWDCert TO FILE = 'C\WebSiteCert'
WITH PRIVATE KEY
( FILE = 'C\WebSiteKey',
DECRYPTION BY PASSWORD = 's#29&^*@!q' ,
ENCRYPTION BY PASSWORD = 's#29&^*@!q'
)
Cannot write into file 'C\WebSiteKey'. Verify that you have write permissions, that the file path is valid, and that the file does not already exist.
What am I doing wrong?
Also One more question and I will add to this since it's same topic:
Is database master key optional or mandatory for encrypting data? This question is from MCTS Exam 70-431.
Which of the following sentences are true for the database master key?(Choose all that apply.)
A. The database master key is optional
B. The database master key is mandatory if you want to encrypt data.
C. The database master key is created automatically when you create the first certificate.
D. The database master key is created manually.
Now answer to this question is A & D according to MCTS. But I myself tried creating certificate without creating master key and it gave me this message:
[Please create a master key in the database or open the master key in the session before performing this operation.]
So I believe it should be A, B & D. Please comment.
Thanx
Hi, sorry about the delays...
I would have incorrectly answered 'D', always think that certificates use database master key : http://msdn.microsoft.com/
But you don't. It does depend on the certificate and if created with "Self Signed" Key, then doesn't need database key.
The backup doesn't work if there is already a file there, and rotten thing doesn't take a variable, so have to exec the backup if using datetime. but should only be backed up once as a recognised name..., so that example below probably just needs to be : BACKUP CERTIFICATE mw_cert_ee_1 TO FILE = 'c:\mysafespot\mw_cert_ee_
Does that make sense ?
MS trick question. For B to be true then the truer answer must be either C or D being manual or auto. We know that C cannot be the truist answer, otherwise all A B and D are unneccesary, and we can create database key. So, the only real question is do we need them at all ? And if you look at that link, it does imply that certificates do hang off a database master key, in which case why wouldn't C be the most correct answer ? Therefore, if we can create them manually ie D then it is highly likely that the only other answer to consider is A .
Well, it depends on use of password... In the example above, it specifies a password as part of the create certificate. If it doesn't have that, then it needs a password somehow and looks for the master key.
From BOL: ENCRYPTION BY PASSWORD = 'password'
Specifies the password that will be used to encrypt the private key. Use this option only if you want to encrypt the certificate with a password. If this clause is omitted, the private key will be encrypted using the database master key.
The above snippet is not overly explicit about "must be this else that" in fact using terms like "optional" tends to paint the wrong picture. Bottom line is there must be a password either at certificate, or master key. By default, the private key is encrypted using the database master key. But, if that does not exist and no password is specified then you get the error.
Further down in BOL we get a better desription :
The ENCRYPTION BY PASSWORD option is not required when the private key will be encrypted with the database master key. Use this option only when the private key will be encrypted with a password. If no password is specified, the private key of the certificate will be encrypted using the database master key. Omitting this clause will cause an error if the master key of the database cannot be opened.
Does that help ? Might take a couple of readings, it almost makes sense the first few reads...
Business Accounts
Answer for Membership
by: mark_willsPosted on 2009-05-14 at 00:33:24ID: 24382395
No, it is a potential problem... Think of it as a database, what do you do about securing a database ? simple, back it up. That is what you need to do with your certificates as well...
,
BACKUP CERTIFICATE certname TO FILE = 'path_to_file'
[ WITH PRIVATE KEY
(
FILE = 'path_to_private_key_file'
ENCRYPTION BY PASSWORD = 'encryption_password'
[ , DECRYPTION BY PASSWORD = 'decryption_password' ]
)
]
To restore you use the create certificate and point it to the file...