Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi team,

I've implement the symmetric key encryption /decryption in sql server using below Query

SQL
CREATE MASTER KEY ENCRYPTION
BY PASSWORD = 'Name@1'
GO

--Certificate
CREATE CERTIFICATE EncryptNameCert
WITH SUBJECT = 'NameCer@1'
GO

--Symmetric Key
CREATE SYMMETRIC KEY NameSymmetKey
WITH ALGORITHM = TRIPLE_DES ENCRYPTION
BY CERTIFICATE EncryptNameCert
GO

-- Alter varchar to varbinary : UserDetails

 ALTER TABLE UserDetails
   add TempName nvarchar(30);
 
  update UserDetails set TempName = Name;
  update UserDetails set Name = null;

  alter table UserDetails alter column Name decimal(1,0);
  alter table UserDetails alter column Name VARBINARY(256);
  

--Encrypt the data : Table - Update existing data : 
OPEN SYMMETRIC KEY NameSymmetKey DECRYPTION
BY CERTIFICATE EncryptNameCert
UPDATE UserDetails
SET 
 CardHolderName = null,
 
GO
UPDATE UserDetails
SET 
 CardHolderName = ENCRYPTBYKEY(KEY_GUID('NameSymmetKey'),TempName),
   
GO



in front-end user need to insert the details at the same need to read. so im trying to implement(string to varbinary /varbinary to string) the same flow through c# code but i couldn't achive the solution. i tried but i always got some issues relate to length related issue or issue occur here too
C#
Convert.FromBase64String()


i have tried so many references 3DES (Triple-DES) in C#[(Triple-DES)]


[msdn]


[triple-des-encryption-and-decryption-using-user-provided-key]


please send me the sample code to fix to execute

What I have tried:

i tried the above link some others also , i need to implement symeetric key with triple DES .i changed the backend DB side. i need to convert the string to varbinary but i cant do the same symmetric conversion in c# with the same. i'm very tired to find the fix please help me out from this.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900