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
会导致一些异常,通知某些证书无效或过期。