create PROCEDURE [dbo].[ProcMyProc](@ClearText nvarchar(50))
AS
BEGIN
OPEN SYMMETRIC KEY MyKey DECRYPTION BY PASSWORD= 'MY_Password_128';
grant view definition on symmetric key ::MyKey to OUTSOURCE/VerticityDev
Declare @Temp varbinary(8000);
Set @Temp =EncryptByKey(Key_GUID('MyKey'),@ClearText);
--close symmetric key MyKey;
select @Temp as temp;
END
exec [dbo].[ProcMyProc] 'ERUM'
sp is created successfully but when i run it ,it says
Msg 15151, Level 16, State 1, Procedure ProcMyProc, Line 4
Cannot find the symmetric key 'MyKey', because it does not exist or you do not have permission.
Msg 15151, Level 16, State 1, Procedure ProcMyProc, Line 5
Cannot find the symmetric key 'MyKey', because it does not exist or you do not have permission.
I'm guessing you are doing this in a query window from within Management Studion - right?
If so then you need GO statements to define the end of the procedure
Code:
create PROCEDURE [dbo].[ProcMyProc](@ClearText nvarchar(50))
AS
BEGIN
OPEN SYMMETRIC KEY MyKey DECRYPTION BY PASSWORD= 'MY_Password_128';
grant view definition on symmetric key ::MyKey to OUTSOURCE/VerticityDev
Declare @Temp varbinary(8000);
Set @Temp =EncryptByKey(Key_GUID('MyKey'),@ClearText);
--close symmetric key MyKey;
select @Temp as temp;
END
GO
exec [dbo].[ProcMyProc] 'ERUM'
I have never used the OPEN SYMMETRIC KEY.
Why are you granting VIEW definition to it from within the SPROC also??
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
yes i m using in sql server 2005 managemnt studio
i put Go statement too .
secondly i have found on certain forum that u need to grant permission for that purpose . after that i change my sp like this
alter PROCEDURE [dbo].[ProcMyProc](@ClearText nvarchar(50))
AS
BEGIN
OPEN SYMMETRIC KEY MyKey DECRYPTION BY PASSWORD= 'MY_Password_128';
grant view definition on symmetric key ::MyKey to noor
Declare @Temp varbinary(8000);
Set @Temp =EncryptByKey(Key_GUID('MyKey'),@ClearText);
close symmetric key MyKey;
select @Temp as temp;
END
GO
but still errors like this
.
Msg 15313, Level 16, State 1, Procedure ProcMyProc, Line 5
The key is not encrypted using the specified decryptor.
Msg 15151, Level 16, State 1, Procedure ProcMyProc, Line 6
Cannot find the user 'noor', because it does not exist or you do not have permission.
Msg 15315, Level 16, State 1, Procedure ProcMyProc, Line 9
The key 'MyKey' is not open. Please open the key before using it.
Have you read any of the MSDN or BOOKS ONLINE help for these functions?
I just read the ENCRYPTBYKEY help and it's complex to say the least. I've never used any of these functions myself - but it sure appears that they are used to "store" encrypted data and then you decrypt on the way out of the DB.
If you cannot get an answer here - try the MSDN Tech Net site...
(I set password field as uniqueidentifier).While storing my data in Database after encryption and I run insert statement in database it insert all the values in the table other than password .
For example if I write
Insert into table1 (login, password) values ( ‘user1’,’x343434343434343fgdfkgdkfgdkg’)
Where ’x343434343434343fgdfkgdkfgdkg’ is encrypted data …
And when I run statement select * from table1
It shows login as user1 but password is blank.
So what should I suppose to do ….so that it store encrypted data as uniqueidentifier..
yes i have bit problem but of different kind.actually i m cabable to encrypt the data but unable to store encrypted data in the database as i mention in my last post
If you are using vb2005 and sql server 2005, I can provide you with a sample project that will show you how to use SYMMETRIC KEY to store a password and display it unencrypted.
This is a project that I wrote to teach myself how to use SYMMETRIC KEY, there are a few problems with it that has nothing to do with SYMMETRIC KEY stuff, so I never got around to fixing them:
Before you use it, you should know that the database location is hardcoded. You will need to change the location to yours.
Code:
Dim strDataBaseFileName As String = "c:\Code Files\symmetricKey\symmetricKeyTest.mdf"
When you click on the Create Database button, you will get an error , click ok and reclick the create button and the database will be created. If you can fix this problem, please let me know.
When you click on the two insert buttons, no response is return, you might want to put a messagebox in them saying the data was inserted.