There is a simple client application for the database created in SQL Server 2014 EXPRESS, it is required to encrypt the data in the cells. Found an algorithm and encryption commands, but using SQL Server. Tell me how to implement encryption and decryption of data in the client. Data is output using DataGredView, editing using TextBox.

Insert commands:

cvetTableAdapter.Insert(textBox2.Text); cvetTableAdapter.Fill(gIBDDDataSet.Cvet); 

Update commands:

 cvetBindingSource.EndEdit(); cvetTableAdapter.Update(gIBDDDataSet.Cvet); cvetTableAdapter.Fill(gIBDDDataSet.Cvet); 

Deletion commands:

 cvetTableAdapter.Delete(Convert.ToInt32(textBox1.Text), textBox3.Text); cvetTableAdapter.Fill(gIBDDDataSet.Cvet); 

Program code to create keys for demonstration. Keys are created in the database itself. There are no problems with this.

 USE [EncryptedDB] GO β€” Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ асиммСтричного ΠΊΠ»ΡŽΡ‡Π°, Π·Π°ΡˆΠΈΡ„Ρ€ΠΎΠ²Π°Π½Π½ΠΎΠ³ΠΎ β€” ΠΏΠ°Ρ€ΠΎΠ»ΡŒΠ½ΠΎΠΉ Ρ„Ρ€Π°Π·ΠΎΠΉ StrongPa$$w0rd! CREATE ASYMMETRIC KEY MyAsymmetricKey WITH ALGORITHM = RSA_2048 ENCRYPTION BY PASSWORD = 'StrongPa$$w0rd!' GO β€” Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ симмСтричного ΠΊΠ»ΡŽΡ‡Π°, Π·Π°ΡˆΠΈΡ„Ρ€ΠΎΠ²Π°Π½Π½ΠΎΠ³ΠΎ β€” асиммСтричным ΠΊΠ»ΡŽΡ‡ΠΎΠΌ. CREATE SYMMETRIC KEY MySymmetricKey WITH ALGORITHM = AES_256 ENCRYPTION BY ASYMMETRIC KEY MyAsymmetricKey GO 

Here is the insert itself with encryption. From here the problems begin, because I do not understand how to implement all this in c #.

 USE [EncryptedDB] GO DECLARE @SymmetricKeyGUID AS [uniqueidentifier] SET @SymmetricKeyGUID = KEY_GUID('MySymmetricKey') IF (@SymmetricKeyGUID IS NOT NULL) BEGIN INSERT INTO [dbo].[CreditCardInformation] VALUES (01, ENCRYPTBYKEY(@SymmetricKeyGUID, N'9876-1234-8765-4321')) 

Data output with decryption. Again, how to implement this in the functionality of the application.

 USE [EncryptedDB] GO SELECT [PersonID] CONVERT([nvarchar](32), DECRYPTBYKEY(CreditCardNumber)) AS [CreditCardNumber] FROM [dbo].[CreditCardInformation] GO 

Help, everything has already been covered. Nowhere is there anything sensible.

  • There are a lot of encryption methods built in . Choose the right one. And how it is applied depends on the method of access to the database. - Alexander Petrov
  • Those. no sense to use the capabilities of SQL Servers? - Maxim Kutenkov
  • Well, why not? Can be used. Only if the data is encrypted in the application, then they are already encrypted over the network. And if on the server, then in open form. - Alexander Petrov
  • Accepted, thanks! - Maxim Kutenkov
  • I was wrong. You can encrypt data on the client (C #), and decrypt it on the server (TSQL), and vice versa. It all depends on what needs to be secured: data storage or data transfer . - Alexander Petrov

0