What's the easiest way to encrypt a file in c#?

后端 未结 5 657
醉话见心
醉话见心 2020-12-19 20:13

Beforehand :

I have read indeed the other topics on SO, but I can\'t find an answer in them.
(The others are about config-files, or a list of techniques)

<
5条回答
  •  误落风尘
    2020-12-19 20:40

    Encryption is trivial with modern libraries: the hard part is securing the key(s).

    So you need to look at what you're trying to secure, and what threats you are trying to secure against.

    To encrypt a file so only the current user can see it on a client workstation, File.Encrypt is a good choice, or DPAPI with the CurrentUser scope.

    For a configuration file on a single server, DPAPI using the LocalMachine scope is a good choice. You then need to make sure only authorized users are able to log in to the server. Here you're essentially delegating key management to Windows.

    For a configuration file on a server farm, you need to share the key between the servers. RsaProtectedConfigurationProvide is a good choice, but you have more work ensuring that all servers have access to the same key, and that it is protected against unauthorized access (e.g. using a DACL).

提交回复
热议问题