gpt4 book ai didi

C#如何在将文本文件读入字符串时对字节进行异或

转载 作者:行者123 更新时间:2023-12-02 22:06:30 25 4
gpt4 key购买 nike

我需要防止一些 child 修改 json 文本文件并将“fartface”放入其中。我当前的代码从文本文件中获取一个字符串,如下所示:

using (StreamReader file = File.OpenText(basePath + "jsontxt"))
{
string s = file.ReadToEnd();

我可以对我的 jsontxt 文件应用异或,这足以防止恶意放屁笑话,但在我的 wpf C# 应用程序中,我不确定如何在文件读入字符串时实现字节异或。

最佳答案

尝试将字符串作为字节数组并简单地使用一些 key 对每个字节进行异或:

Byte[] byteString;
using (StreamReader file = File.OpenText(basePath + "jsontxt"))
{
Byte secretByte = 125;
string s = file.ReadToEnd();
byteString = Encoding.UTF8.GetBytes(s);
foreach(Byte b in byteString)
{
b ^= secretByte;
}
}
//here save stream

关于C#如何在将文本文件读入字符串时对字节进行异或,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16041817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com