文件加密和解密错误-请测试我的代码,看看是否可以找到错误 [英] File encrypt and decrypt error - Test my code please to see if error can be found

查看:146
本文介绍了文件加密和解密错误-请测试我的代码,看看是否可以找到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想测试File.Encrypt和File.Decrypt方法,但出现错误.看了MSDN站点,但没有找到解决我问题的方法.我想念什么吗?

I want to test the File.Encrypt and File.Decrypt methods but I am getting errors. Had a look at the MSDN site but no solution to my problem have I found. Am I missing something?

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");
}

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");
}



单击button1时,我收到一条错误消息,"File.Encrypt("Text.pvf");返回错误异常,不支持该请求."

也许复制我的代码进行测试.也许这将有助于确定错误.
请帮忙解决这个问题,因为我不是什么原因



I am getting an error message when button1 is clicked, "File.Encrypt("Text.pvf");" returns an error exception, "The request is not supported."

Maybe copy my code to test it. Maybe that will help in determining the error.
Please help with this as I don''t what the cause is

推荐答案

我想您是在谈论NotSupportedException.
您可以在上下文中查询该方法的文档 [^ ]: 文件系统不是NTFS" .
I suppose you''re talking about NotSupportedException.
You may look up its meaning in your context cheking out the method''s documentation[^]: "The file system is not NTFS".


已在Win7、64-位,NTFS,它运行完美.可能是您没有写入文件的权限(文件权限,目录权限,文件为只读...).
Tested this with Win7, 64-bit, NTFS and it worked perfectly. Could it be that you don''t have the permission to write to the file (file permission, directory permission, file is read only...). This would also cause the exception mentioned.


标记有System属性的文件和systemroot目录中的文件无法进行加密.
chk,如果这是问题所在.


更改文件路径,然后尝试.
Files marked with the System attribute and files in the systemroot directory cannot b encrypted.
chk if this is the problem.


change file path and try .


这篇关于文件加密和解密错误-请测试我的代码,看看是否可以找到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆