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.
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.
So here are the requirements:
System.Security.*
Ive read Simple insecure two-way "obfuscation" for C# but there is no solution without dependencies.
The various encryption types. The three major encryption types are DES, AES, and RSA.
You can't encrypt something without a key. If there's no key, either anyone can recover the plain-text, or it is unrecoverable to everyone.
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.
Example with constant:
byte xorConstant = 0x53;
string input = "foo";
byte[] data = Encoding.UTF8.GetBytes(input);
for (int i = 0; i < data.Length; i++)
{
data[i] = (byte)(data[i] ^ xorConstant)
}
string output = Convert.ToBase64String(data);
To decode:
byte xorConstant = 0x53;
byte[] data = Convert.FromBase64String(input);
for (int i = 0; i < data.Length; i++)
{
data[i] = (byte)(data[i] ^ xorConstant)
}
string plainText = Encoding.UTF8.GetString(data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With