예제 #1
0
        public static byte[] ReadAllBytes(string path, bool decrypt = true)
        {
            if (!File.Exists(path))
            {
                Debug.LogError("File \"" + path + "\" doesn't exist");
                return(null);
            }

            if (!decrypt)
            {
                return(File.ReadAllBytes(path));
            }

            byte[] bytes = File.ReadAllBytes(path);
            if (bytes.Length == 0)
            {
                return(bytes);
            }

            string line = MCrypt.DecryptByteArray(bytes);

            bytes = MUtil.StringToByteArray(line);

            return(bytes);
        }
예제 #2
0
        public static void WriteAllBytes(string path, byte[] content, bool encrypt = true)
        {
            if (!encrypt)
            {
                File.WriteAllBytes(path, content);
                return;
            }

            string line = MUtil.ByteArrayToString(content);

            content = MCrypt.EncryptString(line);

            File.WriteAllBytes(path, content);
        }
예제 #3
0
        public static void WriteAllText(string path, string content, bool encrypt = true)
        {
            if (!encrypt)
            {
                File.WriteAllText(path, content);
                return;
            }



            byte[] encrypted = MCrypt.EncryptString(content);

            //File.WriteAllBytes(path, encrypted);
            //string text = MUtil.ByteArrayToString(encrypted);
            //File.WriteAllText(path, text);
            File.WriteAllBytes(path, encrypted);
        }
예제 #4
0
        public static string[] ReadAllLines(string path, bool decrypt = true)
        {
            if (!decrypt)
            {
                return(File.ReadAllLines(path));
            }

            /*string content = File.ReadAllText(path);
             *
             * byte[] contentByte = MUtil.StringToByteArray(content);*/

            byte[] contentByte = File.ReadAllBytes(path);
            if (contentByte.Length == 0)
            {
                return(new string[0]);
            }

            string content = MCrypt.DecryptByteArray(contentByte);

            return(MUtil.StringToStringArray(content));
        }