Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2005
    Posts
    74

    Unanswered: Help with EncryptByKey

    hi! guyz..will you help me with this..why is it everytime i execute the T-SQL below it wont decrypt the string I encrypted, the 'encrypt me' string..will you check my code please..thanks in advance!!!

    Code:
    create master key encryption by password = 'p@ssword'
    
    create certificate MyCertificate
    with subject = 'My certificate',
    	 start_date = '08/05/2006'
    
    create symmetric key my_symmetric_key
    	with
    		algorithm = TRIPLE_DES
    		encryption by certificate MyCertificate	
    
    declare @var_enc varbinary(200)
    declare @var_dec nvarchar(200)
    declare @string nvarchar (200)
    
    set @string = 'encrypt me'
    
    select @string
    
    open symmetric key my_symmetric_key
    	decryption by certificate MyCertificate
    
    select @var_enc = EncryptByKey(key_GUID('my_symmetric_key'),@string) 
    
    select @var_enc as 'ENCRYPTED'
    
    select DecryptByKey(@var_enc) as 'DECRYPTED'
    
    close symmetric key my_symmetric_key
    
    drop symmetric key my_symmetric_key
    drop certificate MyCertificate
    drop master key

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    Try converting the result of DecryptByKey to varchar or nvarchar.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •