locked
Encrypt/Decrypt RRS feed

  • Question

  • User-797751191 posted

    Hi

      How to pass string parameters in encrypted form from sql stored procedure and decrypt in c# using request.querystring

    Thanks

    Friday, July 12, 2019 11:03 AM

All replies

  • User-1038772411 posted

    Hi, Jsshivalik

    Please refer below link for your concern.

    https://forums.asp.net/t/1842327.aspx?Sending+encrypted+querystring+to+stored+procedure+and+return+results

    You can also use this sample code hope you will get as you want.

    https://www.aspsnippets.com/Articles/Encrypt-and-Decrypt-QueryString-Parameter-Values-in-ASPNet-using-C-and-VBNet.aspx

    Thanks.

    Friday, July 12, 2019 12:10 PM
  • User283571144 posted

    Hi jsshivalik,

    According to your description, I suggest you could try to use sql server build-in EncryptByPassPhrase function to achive your requirement.

    You could use blelow query to encrypt the querystring firstly.

    declare @pwd varbinary(max) ,@password nvarchar(1000) , @EncrptString nvarchar(max), @pwd2 nvarchar(max)
    set @password ='1234567'
    set @EncrptString= 'teststring'
    
    
    SELECT @pwd = EncryptByPassPhrase( @password, @EncrptString)
    select @pwd
    
    set @pwd2 =  convert(nvarchar(max) ,@pwd, 1)
    select @pwd2

    Result:

    Then you could send th @pwd2 by using the querystring parameter.

    At last, you could use ADO.NET call below sql query to use DecryptByPassPhrase  in asp.ne webform to decrypt the querystring.

    Details, you could refer to below query exmaple:

    declare @pwd varbinary(max) ,@password nvarchar(1000) , @EncrptString nvarchar(max), @pwd2 nvarchar(max)
    set @password ='1234567'
    set @pwd2 =  '0x010000000C3DA5D896795DEB37952BF3703D971B576144468CF31E1BA064ADB39A6115039868C8D069E37E5F'
    select @pwd2
     
    SELECT @EncrptString =CAST( DecryptByPassPhrase(@password , CONVERT(varbinary(max),@pwd2,1) ) as nvarchar(max))
    select @EncrptString

    Result: 

    Best Regards,

    Brando

    Monday, July 15, 2019 3:05 AM