我有,我想創建一個文件C#應用程序保護文件:通過密碼
string fileName = "test.txt"; // a sample file name
// Delete the file if it exists.
if (System.IO.File.Exists(fileName))
{
System.IO.File.Delete(fileName);
}
// Create the file.
using (System.IO.FileStream fs = System.IO.File.Create(fileName, 1024))
{
// Add some information to the file.
byte[] info = new System.Text.UTF8Encoding(true).GetBytes("This is some text in the file.");
fs.Write(info, 0, info.Length);
}
string s = "";
using (System.IO.StreamReader sr = System.IO.File.OpenText(fileName))
{
while ((s = sr.ReadLine()) != null)
{
textBox1.Text += s;
}
}
我需要通過程序之外的密碼保護的文件和文件訪問內該程序沒有密碼。
如何更改片段來完成此任務?
如果你還沒有嘗試過,甚至自己動手做,請參考System.Security.Cryptography命名空間,並給它一展身手。 – Ashigore