Modern software trends

C# Simple Data Encryption

To protect and safely transfer or store the data is an important issue. This tiny code snippet shows how you can easily encrypt any object.
        private static byte[] EncryptData(object obj)
        {
            if (obj == null)
                return null;
            BinaryFormatter bf = new BinaryFormatter();
            using (MemoryStream ms = new MemoryStream())
            {
                bf.Serialize(ms, obj);
                var ar = ms.ToArray();
               // Array.Reverse(ar);
                for(int k=0; k<ar.Length;k++)
                {
                    ar[k] += 1;
                }

                return ar;

            }
        }

Post a Comment

0 Comments