With todays crypto techniques and open libraries, encryption is quite accessible. But I wanted to speak of a simple crypto method, for those who don’t want to store stuff in plain text and want an easy implementation.

Please be warned, this method should not be used for anything more important than basic non-private data, since it can be broken by an average attacker.

Code of the console app is in C#, using .Net Core 3.1 and written on Visual Studio. It can be adapted to any environment since it doesn’t depend on any crypto library.

Let’s look at the main code first, Program.cs:

using System;

namespace SimpleCrypto
{
    class Program
    {
        [Serializable]
        public struct DataStruct
        {
            public int iTest;
            public float fTest;
            public string sTest;
            public bool bTest;
        }
        static void Main(string[] args)
        {
            // console will use UTF8 encoding
            Console.OutputEncoding = new System.Text.UTF8Encoding();
            // create data manager and data structure
            DataEncryptor dataEncryptor = new DataEncryptor();
            DataStruct dataStruct = new DataStruct();
            // fill data
            dataStruct.iTest = 12;
            dataStruct.fTest = 34.56f;
            dataStruct.sTest = "Hello öçşığü!";
            dataStruct.bTest = true;
            // encrypt & save data
            dataEncryptor.DataSave(dataStruct);
            // load & decrypt data
            dataStruct = (DataStruct)dataEncryptor.DataLoad();
            // show data
            Console.WriteLine("* Encrypted & decrypted data:");
            Console.WriteLine("iTest=" + dataStruct.iTest);
            Console.WriteLine("fTest=" + dataStruct.fTest);
            Console.WriteLine("sTest=" + dataStruct.sTest);
            Console.WriteLine("bTest=" + dataStruct.bTest);
            Console.WriteLine();
        }
    }
}

#csharp #cryptography #net-core #xor-cipher

A Simple Crypto Method
1.25 GEEK