fjsj
fjsj

Reputation: 11240

How to create a file with FileOptions.Encrypted in C#?

I'm trying to create a file with FileOptions.Encrypted using the following code:

FileStream fout = File.Create("out.txt", 2 << 12, FileOptions.Encrypted);

But I'm getting System.UnauthorizedAccessException. I've even tried to create the file in my Desktop, but the error persists.

What is the correct way of creating a file with FileOptions.Encrypted option?

Upvotes: 1

Views: 589

Answers (1)

Kyle W
Kyle W

Reputation: 3752

From the MSDN document, an UnauthorizedAccessException is thrown when:

Encrypted is specified for options and file encryption is not supported on the current platform. 

Upvotes: 1

Related Questions