Modern software trends

C# Simple Data Decryption

Sometimes is the data protection one of the most important tasks for a software developer. This is the simplestway you can do data decryption (use encryption from the previous post)
        public static T DecryptData<T>(byte[] data)
        {
            try
            {
                if (data == null)
                    return default(T);

                for (int k = 0; k < data.Length; k++)
                {
                    data[k] -= 1;
                }
                BinaryFormatter bf = new BinaryFormatter();
                using (MemoryStream ms = new MemoryStream(data))
                {
                    object obj = (T)bf.Deserialize(ms);
                    return (T)obj;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Post a Comment

0 Comments