best and most secure way to encrypt data

banoo 1 Reputation point
2021-06-14T13:29:24.607+00:00

Hello.
I have a program written with .net mvc(c#) and sql server 2014
I want to store some information encrypted in the database.
What is the best and most secure way to encrypt data?
And that encryption is better done in the sql or in C#?

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,254 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,713 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,247 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 48,281 Reputation points
    2021-06-14T14:21:07.14+00:00

    Depends on what your requirements are. If you need to store data even at rest then encryption in SQL is the only way to do that. Otherwise anyone with DB access can read the unencrypted data. But it gets a lot harder as you'll also need to ensure that only specific accounts can decrypt the data otherwise, again, anyone with DB access can read it. Of course this level of security is really only needed for sensitive data that you have no choice but to store for whatever business reasons such as SSNs or CC numbers. Of course the best option is to never store any of this and then encryption isn't needed.

    If you need to share data between a client and a server (whatever that means to you) then C# is probably the better route. For example if you're communicating between two machines then HTTPS (already encrypted) is expected. For non-HTTPS then you should encrypt on one side and decrypt on the other, if needed.

    As for the mot secure encryption then the general recommendation is asymmetric with the largest key both sides support. Refer to this helpful link in MSDN. You'll want the most secure algorithm with the largest key that you can manage. Of course this is expensive so if you don't need as much security then symmetric is easier but more vulnerable.

    .NET docs have a good summary of all this to read.


  2. Tom Phillips 17,716 Reputation points
    2021-06-17T14:41:02.88+00:00

    There are several options. The answer to your question depends on who exactly you are trying to hide the encrypted data from?

    0 comments No comments