troubleshooting Question


Avatar of ukerandi
ukerandiFlag for United Kingdom of Great Britain and Northern Ireland asked on
EncryptionMicrosoft SQL Server 2008.NET ProgrammingVisual Basic.NET
4 Comments1 Solution489 ViewsLast Modified:
Following code is working FINE at my computer. im login as Db_Owner

When im runing at some collegue machine, Following error
The key is not encrypted using the specified decryptor

I gave grant to run, I created Group called Group1 and add the users and give the
access as Public DB_Datareader and DB_DataReader
and also gave Following
GRANT EXECUTE ON Table1 TO [Server01\Group1]; // Table name
GRANT EXECUTE ON TestKey TO [Server01\Group1]; //stored procedure name
Create Key code
 string TempKey = txtKeyNumber.Text.ToString();
                string strCreateSymmeticKey;
                strCreateSymmeticKey="CREATE SYMMETRIC KEY TestSymmetricKey";
                strCreateSymmeticKey=strCreateSymmeticKey+" "+"WITH ALGORITHM = AES_256";
                strCreateSymmeticKey = strCreateSymmeticKey + " " + "ENCRYPTION BY PASSWORD = '" + TempKey + "'";

                cmd.CommandText = strCreateSymmeticKey;
Sored Procedure
Create Procedure TestKey
@Empnumber varchar(7),
@KeyNumber nvarchar(100)

DECLARE @open nvarchar(4000)
SET @open = 'OPEN SYMMETRIC KEY TestSymmetricKey  DECRYPTION BY PASSWORD =' + quotename (@KeyNumber,'''')
EXEC sp_executesql @open

SELECT CONVERT(NVARCHAR(4000),DecryptByKey(salary)) FROM (SELECT *,ROW_NUMBER() OVER(PARTITION BY emp_num ORDER BY RecordDate DESC)'RowNum'  FROM Table1  )sub
WHERE RowNum = 1 and emp_num=@Empnumber
Calling Code
======================================================== code
connection 1= New SqlConnection(connetionString)
co1.Connection =connection
co1.CommandType = CommandType.StoredProcedure
co1.parameters.Add("@KeyNumber", sqlDBType.varchar).value = KeyValue1
The key is not encrypted using the specified decryptor

Could some one show me where is the mistake or any advice highly appriciate.
Vitor Montalvão
IT Engineer
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros