Sql-server – Opening Symmetric Keys

encryptionsql server

I am trying to open a symmetric key I created in a database, but it doesn't seem to be working. I am executing the query as dbo and it even says that it is completed successfully. However, the value for the key being open is still set to false and I cannot move forward. I am not sure how to proceed.

CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'password'
go

CREATE CERTIFICATE Certificate1
WITH SUBJECT = 'Subject';
go

CREATE SYMMETRIC KEY SymmetricKey1
WITH ALGORITHM = AES_256
ENCRYPTION BY CERTIFICATE Certificate1;
go

OPEN SYMMETRIC KEY SymmetricKey1
DECRYPTION BY CERTIFICATE Certificate1;
go

I can create the master key, certificate, and symmetric key just fine. That OPEN statement just doesn't work. It doesn't return any errors like I said, it just completes successfully without actually doing anything. This is for a class and I am totally lost. I feel like I am doing it correctly and am not sure what to change. I have tried recreating everything and even deleted the database itself.

Any advice would be welcome.

Best Answer

Each Go statement lets SQL Server know that the preceding commands are meant to be a single batch. This works for the create statements, but I suspect that if you try to use the symmetric key in a command after the batch, it will not be open. Remove the Go statements, then try to use the symmetric key after the open statement.