尝试使用文件加密,但遇到错误,file.Encrypt(FileName)返回异常

本文关键字:Encrypt file FileName 异常 返回 错误 遇到 文件 加密 | 更新日期: 2023-09-27 18:22:17

我尝试了代码项目帮助以及MSDN,但没有成功。这是我的测试代码的副本,返回一个异常:

private void button2_Click(object sender, EventArgs e)
{
    File.Decrypt("Text.pvf");
    string[] DataFile = File.ReadAllLines("Text.pvf");
    if (DataFile[5] == "6")
        MessageBox.Show("Encrypt/Decrypt successful");
   //Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
    string[] DataFile = new string[6];
    DataFile[0] = "1";
    DataFile[1] = "2";
    DataFile[2] = "3";
    DataFile[3] = "4";
    DataFile[4] = "5";
    DataFile[5] = "6";
    File.WriteAllLines("Text.pvf", DataFile);
    File.Encrypt("Text.pvf");
}

在"File.Encrypt("Text.pvf");"行,我得到一个IOException,上面写着:"不支持该请求。"。现在首先调用button1方法。我不知道为什么会出现这个错误。

我的电脑:Windows7 64位,.net 4.0,文件系统是File.Encryption方法所需的NTFS。

请复制并粘贴我的代码,看看你是否能发现错误。也许我错过了什么。请帮忙。

尝试使用文件加密,但遇到错误,file.Encrypt(FileName)返回异常

您使用的是Windows 7家庭版吗?

在Windows 7 Home Edition中,它不受支持。http://www.pcreview.co.uk/forums/encrypt-contents-secure-data-greyed-out-t171160.html

您的代码可以在我的计算机上运行WPF App 4.0客户端配置文件中的Visual Studio 2010。因此,它必须与您的用户帐户和权限有关。尝试将文件保存在另一个目录中,如IsolatedStorage