简体   繁体   中英

Can you help me on file.encrypt?

I would like to encrypt and decrypt files but this shows me an error "This request is not supported" and "Invalid descriptor". Can you help me ?

I have two methods AddEncryption and RemoveEncryption which encrypts and decrypts the file passed in FileName.

public static void Main()
{
    try
    {
        string FileName = "C:\Users\PORTABLEHP\Documents\a.txt";
        Console.WriteLine("Encrypt" + FileName);
        AddEncryption(FileName);
        Console.WriteLine("Decrypt" + FileName);
        RemoveEncryption(FileName);
        Console.WriteLine("Done");
    }
    catch(Exception ex)
    {
        Console.WriteLine(ex);
    }
    Console.ReadLine();
}

public static void AddEncryption(string FileName)
{
    File.Encrypt(FileName);
}

public static void RemoveEncryption(string FileName)
{
    File.Decrypt(FileName);
}

The limitation of File.Encrypt method has been described at File.Encrypt

Important

This API is only supported on Windows platforms that are able to use the NTFS Encrypting File System (EFS). Any attempt to use this on non-Windows systems, Windows Home Edition systems, or non-NTFS drives results in a PlatformNotSupportedException or NotSupportedException, depending on the situation .

Use of this API in .NET Core is not recommended; it is included to enable portability for applications that move to .NET Core but still explicitly target Windows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM