问题描述
我需要一个简单的算法来加密/解密的字符串。像Base64的却多了几分安全。它不是关键任务。
我需要的是一些字符串操作。不一样容易复制的字符串,并使用一个简单的基地64解码器,使其可读。
I need a simple algorithm to encrypt / decrypt a string. Something like Base64 but a little more secure. It is not mission critical.All I need is some string manipulation. Not as easy as copy the string and make it human readable using a simple base 64 decoder.
由于使用.NET的核心是创建我的应用程序,它运行在Windows和苹果电脑。 我面临的问题是,为了使用 System.Security
在Mac上,我需要OpenSSL的安装。由于我没有sudo访问,我不能安装它。
Since my app is created using .NET Core, it runs on windows and mac. The problem i am facing is that in order to use System.Security
on mac, i need openssl to be installed. Since i dont have sudo access, i cant install it.
因此,这里的要求是:
- 简单的字符串加密
- 在
System.Security没有依赖性。*
- Simple String Encryption
- No Dependencies on
System.Security.*
香港专业教育学院读但没有解决方案,无需依赖关系。
Ive read Simple two-way encryption for C# but there is no solution without dependencies.
推荐答案
如果您正在寻找混淆,而不是安全性,您可以XOR具有恒定或输出字符串与不断的以恒定的种子初始化PRNG
If you are looking for obfuscation rather than security, you could XOR the string with a constant or the output of a PRNG initialized with a constant seed.
例如:
byte xorConstant = 0x53;
string input = "foo";
byte[] data = Encoding.UTF8.GetBytes(input);
for (int i = 0; i < data.Length: i++)
{
data[i] = data[i] ^ xorConstant;
}
string output = Convert.ToBase64String(data);
要解码:
byte xorConstant = 0x53;
byte[] data = Convert.FromBase64String(input);
for (int i = 0; i < data.Length: i++)
{
data[i] = data[i] ^ xorConstant;
}
string plainText = Encoding.UTF8.GetString(data);
这篇关于不依赖简单的字符串加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!