How FileAttributes.Encrypted work in C#?

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

I didn't find any example on google... Can anyone show how it works? And when folders and files will be encrypted how to decrypt them?

Link: FileAttributes Enumeration

回答1:

The FileAttributes.Encrypted flag tells you whether a file or folder has been encrypted by the NTFS file system. This option is available to users by right-clicking a file, selecting Properties, then clicking the Advanced button. There is an option "Encrypt contents to secure data" which is what the FileAttributes.Encrypted flag corresponds to.

You can use the File.Encrypt / File.Decrypt methods to encrypt or decrypt a file or folder. Note that you can only decrypt something that was encrypted by the current user.



回答2:

Simply use the following piece of code for File encryption identification:

FileAttributes attributes = File.GetAttributes("C:\testfile.txt"); if ((attributes & FileAttributes.Encrypted) == FileAttributes.Encrypted) {     Console.WriteLine("Encrypted file"); } else {     Console.WriteLine("Not Encrypted file"); } 

Happy Coding...



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!