日期:2014-05-20  浏览次数:20958 次

如何创建一个文件,这个文件别人用文本编辑器打不开,但是自己的程序却可以取得文本。。。。
如题。。。这个问题已经困绕我Long   Time了。。。。。

------解决方案--------------------
public void FileEncoder(string AFileName, string AStr, string AKey)
{
byte[] vStrBytes = Encoding.Default.GetBytes(AStr);
byte[] vKeyBytes = Encoding.Default.GetBytes(AKey);
int j = 0;
for (int i = 0; i < vStrBytes.Length; i++)
{
vStrBytes[i] ^= vKeyBytes[j];
j = (j + 1) % vKeyBytes.Length;
}
FileStream vFileStream = new FileStream(
AFileName, FileMode.Create, FileAccess.Write);
vFileStream.Write(vStrBytes, 0, vStrBytes.Length);
vFileStream.Close();
}
public string FileDecoder(string AFileName, string AKey)
{
if (!File.Exists(AFileName)) return null;
byte[] vKeyBytes = Encoding.Default.GetBytes(AKey);
FileStream vFileStream = new FileStream(
AFileName, FileMode.Open, FileAccess.Read);
byte[] vStrBytes = new byte[vFileStream.Length];
vFileStream.Read(vStrBytes, 0, (int)vFileStream.Length);
vFileStream.Close();
int j = 0;
for (int i = 0; i < vStrBytes.Length; i++)
{
vStrBytes[i] ^= vKeyBytes[j];
j = (j + 1) % vKeyBytes.Length;
}
return Encoding.Default.GetString(vStrBytes);
}
private void button1_Click(object sender, EventArgs e)
{
FileEncoder(@ "C:\temp\temp.txt ", "Zswang 路过 ", "abcdefghijklmnop ");
}

private void button2_Click(object sender, EventArgs e)
{
Text = FileDecoder(@ "C:\temp\temp.txt ", "abcdefghijklmnop ");
}