SQL Server Developer Center > SQL Server Forums > SQL Server Security > Problem Opening Symmetric Key with passed "password"
Ask a questionAsk a question
 

AnswerProblem Opening Symmetric Key with passed "password"

  • Thursday, November 05, 2009 5:07 AMbarkingdog Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    We call "Open symmetric key" from a stored proc, passing in the password like this:

    ...

    OPEN SYMMETRIC KEY DECRYPTION BY PASSWORD = @PassWord

    ...

    @Password is declared as varchar (100) in the stored proc input argument section but the statement does not pass the t-sql syntax check.  The complaint is that @Password is not a String.  (Really?)  What is the correct syntax then?

    TIA,

    barkingdog

Answers

  • Thursday, November 05, 2009 7:32 AMLekss Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi <

    I am not sure if this going to help you , can you give a try on this

    CREATE

    PROC [dbo].[something]

    @Password

    sysname

    AS

    DECLARE

    @open nvarchar(200)

    SET

    @open = 'OPEN SYMMETRIC KEY symmkeyname DECRYPTION BY PASSWORD =' + quotename (@password,'''')

    EXEC

    sp_executesql @open

    But i do accept what BOB says is true .


    Thanks, Leks
  • Thursday, November 05, 2009 7:55 PMRaul Garcia - MSModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    BTW. There is a Microsoft connect issue already open requesting parameterization of the OPEN SYMMETRIC KEY DDL: https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=369270.

    I would really recommend voting for it (that makes it easier for us to triage customer requests) and continue providing us with feedback.

      Thanks a lot in advance.
      -Raul Garcia
       SDE/T
       SQL Server Engine


    This posting is provided "AS IS" with no warranties, and confers no rights.

All Replies

  • Thursday, November 05, 2009 6:43 AMBob BeaucheminMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    The OPEN SYMMETRIC KEY statement can't be parameterized, it requires a
    literal string value if you use the "password=" clause.

    Cheers,
    Bob Beauchemin

  • Thursday, November 05, 2009 7:32 AMLekss Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi <

    I am not sure if this going to help you , can you give a try on this

    CREATE

    PROC [dbo].[something]

    @Password

    sysname

    AS

    DECLARE

    @open nvarchar(200)

    SET

    @open = 'OPEN SYMMETRIC KEY symmkeyname DECRYPTION BY PASSWORD =' + quotename (@password,'''')

    EXEC

    sp_executesql @open

    But i do accept what BOB says is true .


    Thanks, Leks
  • Thursday, November 05, 2009 7:55 PMRaul Garcia - MSModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    BTW. There is a Microsoft connect issue already open requesting parameterization of the OPEN SYMMETRIC KEY DDL: https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=369270.

    I would really recommend voting for it (that makes it easier for us to triage customer requests) and continue providing us with feedback.

      Thanks a lot in advance.
      -Raul Garcia
       SDE/T
       SQL Server Engine


    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Friday, November 06, 2009 1:42 AMbarkingdog Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks for the replies.  It's  very natural to invoke "Open key" in a stored proc, passing in the Passphrase as a parameter.  Dynamic sql works but prevents effective pre-compilation of the stored proc containing the dynamic sql. More a workaround than a highly quality  solution.


    Barkingdog

    P.S. I voted for the issue on Microsoft connect.
    • Edited bybarkingdog Friday, November 06, 2009 1:43 AMAdded P.S.
    •  
  • Monday, November 16, 2009 9:50 AMChunSong Feng -MSFTMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    P.S. I voted for the issue on Microsoft connect.
    Hi,

    You may post the link here, it will beneficial to other members who have the same problems.

    ChunSong Feng
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.