Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 检查文件是否加密_C#_.net_Encryption_Rijndaelmanaged - Fatal编程技术网

C# 检查文件是否加密

C# 检查文件是否加密,c#,.net,encryption,rijndaelmanaged,C#,.net,Encryption,Rijndaelmanaged,根据这个,我对文件进行了加密和解密。 在代码的末尾,我将文件属性设置为加密的 fsIn.Close(); cs.Close(); fsCrypt.Close(); // Mark the file as Encrypted File.SetAttributes(outputFile, File.GetAttributes(outputFile) | FileAttributes.Encrypted); 当我完成解密时 // Mark the file Decrypted File.SetAtt

根据这个,我对文件进行了加密和解密。 在代码的末尾,我将文件属性设置为
加密的

fsIn.Close();
cs.Close();
fsCrypt.Close();
// Mark the file as Encrypted
File.SetAttributes(outputFile, File.GetAttributes(outputFile) | FileAttributes.Encrypted);
当我完成解密时

// Mark the file Decrypted
File.SetAttributes(outputFile, File.GetAttributes(outputFile) & ~FileAttributes.Encrypted);
下面是我如何检查的:

public static bool IsFileEncrypted(string filePath)
{
   FileAttributes attributes = File.GetAttributes(filePath);
   return (attributes & FileAttributes.Encrypted) == FileAttributes.Encrypted;
}
问题是,变量
属性
仅显示
存档
属性


如何检查文件是否加密?是否有其他解决方案?

请注意,属性是文件系统是否加密了该文件,而不是您。您是否检查了该文件是否已加密?它可能存储在不支持加密的文件系统中?我需要通过文件系统检查它?是和否。取决于您想要什么。如果使用AES或rijndael加密文件,则可以选择密码,也无需设置加密标志。或者让操作系统进行加密,然后使用(如果我没记错的话)
File.Encrypt
。这样,您就不能指定密码,加密文件只能由加密该文件的用户帐户使用/解密。好的,使用
file.Encrypt
会导致一些异常,通知某些证书无效或过期。