Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Information can be found in every C# application to be used as a unique salt for encryption?

Tags:

c#

dpapi

What information can be found in every C# application that can be used as a unique salt for encryption, including for web applications, windows services and wcf layers?

I would like to create a library that allows easy encryption of sensitive data stored in configuration files, using the (DPAPI) System.Security.Cryptography.ProtectedData.Protect() and System.Security.Cryptography.ProtectedData.Unprotect() methods.

The library will also be used by a separate application I'm making that can encrypt and decrypt config values outside of the applications that are using the values, allowing updates to config files without recompiling everything or needing access to the original source, although access to the source should always be available.

The salt must be simple enough to enter manually in the separate application (for instance, a GUID would be difficult to identify).

System.Reflection.Assembly.GetEntryAssembly() appears promising, if that is the assembly of the application/service invoking this library I'm making, I could use something in there. First thoughts were "make the salt the config file name the encrypted data is being stored in...", but for websites the config file is always 'web.config'.

Any other thoughts welcome.

Updates...

'GetExecutingAssembly()'... how does that differ from 'GetEntryAssembly()'?

like image 918
Ninjanoel Avatar asked Mar 21 '13 10:03

Ninjanoel


People also ask

What does every C program have?

Every C program has a primary (main) function that must be named main. If your code adheres to the Unicode programming model, you can use the wide-character version of main, wmain. The main function serves as the starting point for program execution.

What is C mostly used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...


1 Answers

Every application/assembly has a version number, this could be an option.

System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
like image 113
LukeHennerley Avatar answered Sep 19 '22 10:09

LukeHennerley