您可以使用 base64 编码对它们进行编码。就像内容被视为二进制一样->它可以是任何类型的文件。但当然,在配置文件中,您将无法读取文件的内容。
这里是 Base64 编码/解码的片段
//Encode
string filePath = "";
string base64encoded = null;
using (StreamReader r = new StreamReader(File.OpenRead(filePath)))
{
byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(r.ReadToEnd());
base64encoded = System.Convert.ToBase64String(data);
}
//decode --> write back
using(StreamWriter w = new StreamWriter(File.Create(filePath)))
{
byte[] data = System.Convert.FromBase64String(base64encoded);
w.Write(System.Text.ASCIIEncoding.ASCII.GetString(data));
}
在 VB.NET 中:
Dim filePath As String = ""
Dim base64encoded As String = vbNull
'Encode()
Using r As StreamReader = New StreamReader(File.OpenRead(filePath))
Dim data As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(r.ReadToEnd())
base64encoded = System.Convert.ToBase64String(data)
End Using
'decode --> write back
Using w As StreamWriter = New StreamWriter(File.Create(filePath))
Dim data As Byte() = System.Convert.FromBase64String(base64encoded)
w.Write(System.Text.ASCIIEncoding.ASCII.GetString(data))
End Using