示例#1
0
    public static void EncodeConfigFile()
    {
        if (SystemConfig.Instance.IsEncryptConfigFile == false)
        {
            return;
        }

        List <string> configList = new List <string>();

        MyFileUtil.GetFileList(MyFileUtil.InnerConfigDir, ref configList, ".xml");

        foreach (string fileName in configList)
        {
            if (fileName.EndsWith(".meta") == true)
            {
                continue;
            }

            byte[] data = File.ReadAllBytes(fileName);
            data = DESCrypto.Encrypt(data, MyFileUtil.EncryptKey);
            File.WriteAllBytes(fileName + MyFileUtil.EncryptXMLFileSuffix, data);
            //MyFileUtil.DeleteFile(fileName);
        }

        AssetDatabase.Refresh();
        Debug.Log("加密配置文件结束");
    }
示例#2
0
        byte[] Decrypt(byte[] buffer, int offset = 0)
        {
            var empty = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 };
            var des   = new DESCrypto(empty, empty);

            return(des.Decrypt(offset == 0 ? buffer : buffer.Sub(offset)));
        }
示例#3
0
        public static VerifyMachineCode_DES GetEncode_DES()
        {
            VerifyMachineCode_DES ret = new VerifyMachineCode_DES();
            string str1 = ReadSystemHardDeviceParam.GetHardDisk_SerialNumber().Trim();
            string str2 = ReadSystemHardDeviceParam.GetCPU_SerialNumber().Trim();
            string str3 = ReadSystemHardDeviceParam.GetMacAddrs().Trim();
            string str4 = ReadSystemHardDeviceParam.GetMasterBoard_SerialNumber().Trim();

            byte[] b1 = Encoding.ASCII.GetBytes(str1);
            byte[] b2 = Encoding.ASCII.GetBytes(str2);
            byte[] b3 = Encoding.ASCII.GetBytes(str3);
            byte[] b4 = Encoding.ASCII.GetBytes(str4);
            byte[] ID = new byte[8];
            for (int i = 0; i < 8; i++)
            {
                try
                {
                    ID[i] = (byte)(b1[i] ^ b2[i] ^ b3[i] ^ b4[i]);
                }
                catch// (System.Exception ex)
                {
                    ID[i] = (byte)'w';
                }
            }
            lcyHashCal lcy = new lcyHashCal();

            byte[]    Encode = lcy.HashCal(ID, lcyNum);
            DESCrypto des    = new DESCrypto();

            ret.ID     = des.EncryptString(StringsFunction.byteToHexStr(ID, ""), "wfMaCovf", "Machincd");
            ret.Encode = des.EncryptString(StringsFunction.byteToHexStr(Encode, ""), "wfMaCovf", "Machincd");
            return(ret);
        }
示例#4
0
        private void btn_Decrypt_Click(object sender, EventArgs e)
        {
            String key  = textBox_Key.Text.Trim(),
                   iv   = textBox_IV.Text.Trim(),
                   body = textBox_Body.Text.Trim();

            if (String.IsNullOrEmpty(key))
            {
                MessageBox.Show("秘钥不能为空!", "温馨提示");
                return;
            }

            if (String.IsNullOrEmpty(iv))
            {
                MessageBox.Show("偏移量不能为空!", "温馨提示");
                return;
            }


            if (String.IsNullOrEmpty(body))
            {
                MessageBox.Show("待处理文本不能为空!", "温馨提示");
                return;
            }

            try
            {
                textBox_Result.Text = DESCrypto.Decryptor(body, key, iv);
            }
            catch (Exception ex)
            {
                MessageBox.Show("解密失败:" + ex.Message, "错误");
            }
        }
示例#5
0
        byte[] Encrypt(byte[] buffer)
        {
            var empty = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 };
            var des   = new DESCrypto(empty, empty);

            return(des.Encrypt(buffer));
        }
示例#6
0
        internal static string EncryptAndSign(string txt)
        {
            string sign    = Md5Encrypt(txt + HeaderContextHelper.PRIVATE_KEY);
            string content = DESCrypto.Encrypt(txt);

            return(content.Length.ToString() + ";" + content + sign);
        }
示例#7
0
        private void btn_CreateKey_Click(object sender, EventArgs e)
        {
            var keyValue = DESCrypto.CreatedKey();

            textBox_Key.Text = keyValue.Key;
            textBox_IV.Text  = keyValue.Value;
        }
示例#8
0
    //存储配置文件数据
    public static void WriteDataInCacheDir(string filePath, string text)
    {
        filePath = OuterDir + "/" + filePath;
        string dir = GetParentDir(filePath);

        if (Directory.Exists(dir) == false)
        {
            Directory.CreateDirectory(dir);
        }

        //加密
        if (SystemConfig.Instance.IsEncryptConfigFile)
        {
            if (filePath.EndsWith(EncryptXMLFileSuffix) == false)
            {
                filePath = filePath + EncryptXMLFileSuffix;
            }

            byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(text);
            data = DESCrypto.Encrypt(data, EncryptKey);
            File.WriteAllBytes(filePath, data);
        }
        else
        {
            File.WriteAllText(filePath, text);
        }
    }
示例#9
0
    public static void ReadConfigDataInStreamingAssetsAsync(string filePath, Action <string> callback)
    {
        if (SystemConfig.Instance.IsEncryptConfigFile && filePath.EndsWith(EncryptXMLFileSuffix) == false)
        {
            filePath = filePath + EncryptXMLFileSuffix;
        }

        byte[] data = ReadConfigDataInStreamingAssetsImp(filePath);
        //解密
        if (SystemConfig.Instance.IsEncryptConfigFile)
        {
            DESCrypto.DecryptAsync(data, MyFileUtil.EncryptKey, (decryptedData) => {
                string result = System.Text.UTF8Encoding.UTF8.GetString(decryptedData);
                callback(result);
            });
        }
        else
        {
            string result = System.Text.UTF8Encoding.UTF8.GetString(data);
            if (callback != null)
            {
                callback(result);
            }
        }
    }
示例#10
0
        public static SoftVerifyData GetVerifyData(string soft)
        {
            RegistryKey key      = Registry.LocalMachine;
            RegistryKey software = key.OpenSubKey("software\\" + soft);
            DESCrypto   des      = new DESCrypto();
            string      desstr   = "";

            if (software == null)//不存在
            {
                throw (new CryptographicException("系统关键数据丢失"));
//                 software = key.CreateSubKey("software\\" + soft);//首次运行
//                 desstr = des.EncryptString(DateTime.Now.ToString("yyyy-MM-dd"), "wfsoftvf", "verifyfd");
//                 software.SetValue("FirstTime", desstr);
//                 desstr = des.EncryptString(DateTime.Now.ToString("yyyy-MM-dd"), "wfsoftvf", "verifycd");
//                 software.SetValue("CurTime", desstr);
//                 desstr = des.EncryptString("0", "wfsoftvf", "verifyud");
//                 software.SetValue("UsedDays", desstr);
//                 desstr = des.EncryptString("0", "wfsoftvf", "verifyut");
//                 software.SetValue("UsedTimes", desstr);
            }
            SoftVerifyData ret = new SoftVerifyData();

            desstr        = software.GetValue("FirstTime").ToString();
            ret.FirstTime = DateTime.Parse(des.DecryptString(desstr, "wfsoftvf", "verifyfd"));
            desstr        = software.GetValue("CurTime").ToString();
            ret.CurTime   = DateTime.Parse(des.DecryptString(desstr, "wfsoftvf", "verifycd"));
            desstr        = software.GetValue("UsedDays").ToString();
            ret.UsedDays  = Int32.Parse(des.DecryptString(desstr, "wfsoftvf", "verifyud"));
            desstr        = software.GetValue("UsedTimes").ToString();
            ret.UsedTimes = Int32.Parse(des.DecryptString(desstr, "wfsoftvf", "verifyut"));
            return(ret);
        }
示例#11
0
        private void btn_Encrypt_Click(object sender, EventArgs e)
        {
            String key  = textBox_Key.Text.Trim(),
                   iv   = textBox_IV.Text.Trim(),
                   body = textBox_Body.Text.Trim();

            if (String.IsNullOrEmpty(key))
            {
                MessageBox.Show("秘钥不能为空!", "温馨提示");
                return;
            }

            if (String.IsNullOrEmpty(iv))
            {
                MessageBox.Show("偏移量不能为空!", "温馨提示");
                return;
            }


            if (String.IsNullOrEmpty(body))
            {
                MessageBox.Show("待处理文本不能为空!", "温馨提示");
                return;
            }

            textBox_Result.Text = DESCrypto.Encryptor(body, key, iv);
        }
示例#12
0
        /// <summary>
        /// 可选择使用 DES/RSA 双向加密函数
        /// </summary>
        /// <param name="str">待加密的字符串</param>
        /// <param name="keyValue">对称加密密钥(密钥长度能且只能是8个字母) </param>
        /// <param name="privateKeyFilePath">非对称加密的私钥文件地址</param>
        /// <returns>string</returns>
        public static string EncryptString(string str, string keyValue, string privateKeyFilePath)
        {
            string strResult = str;

            if (!StringsFunction.CheckValiable(str))
            {
                return(strResult);
            }


            // 判断是否指定了对称加密的密钥, 指定则采用 DES 对称加密算法进行加密
            if (StringsFunction.CheckValiable(keyValue))
            {
                DESCrypto dc = new DESCrypto();
                strResult = dc.EncryptString(strResult, keyValue, keyValue);
            }


            // 判断非对称加密的私钥文件是否指定,指定则使用非对称加密算法(RSA)对其进行二次加密
            if (StringsFunction.CheckValiable(privateKeyFilePath))
            {
                string          privateKey = FileOP.ReadFile(GetRealFile(privateKeyFilePath));
                Regex           r          = new Regex(@"<Modulus>(.*?)</Exponent>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                MatchCollection mc         = r.Matches(privateKey);
                string          publicKey  = "<RSAKeyValue><Modulus>" + mc[0].Groups[1].Value + "</Exponent></RSAKeyValue>";


                RSACrypto rc = new RSACrypto();
                strResult = rc.RSAEncrypt(publicKey, strResult);
            }

            return(strResult);
        }
示例#13
0
        /// <summary>
        /// 可选择使用 DES/RSA 双向解密函数
        /// </summary>
        /// <param name="str">待解密的字符串</param>
        /// <param name="privateKeyFilePath">非对称加密的私钥文件地址</param>
        /// <param name="keyValue">对称加密密钥(密钥长度能且只能是8个字母)</param>
        /// <returns>string</returns>
        public static string DecryptString(string str, string privateKeyFilePath, string keyValue)
        {
            string strResult = str;

            if (!StringsFunction.CheckValiable(str))
            {
                return(strResult);
            }


            // 判断非对称加密的私钥文件是否指定,指定则使用非对称加密算法(RSA)对其进行解密
            if (StringsFunction.CheckValiable(privateKeyFilePath))
            {
                string privateKey = FileOP.ReadFile(GetRealFile(privateKeyFilePath));

                RSACrypto rc = new RSACrypto();
                strResult = rc.RSADecrypt(privateKey, strResult);
            }


            // 判断是否指定了对称加密的密钥, 指定则采用 DES 对称加密算法进行解密
            if (StringsFunction.CheckValiable(keyValue))
            {
                DESCrypto dc = new DESCrypto();
                strResult = dc.DecryptString(strResult, keyValue);
            }

            return(strResult);
        }
示例#14
0
    public static void ReadConfigDataInCacheDirAsync(string filePath, Action <string> callback)
    {
        string newPath = OuterConfigDir + filePath;

        if (SystemConfig.Instance.IsEncryptConfigFile && newPath.EndsWith(EncryptXMLFileSuffix) == false)
        {
            newPath = newPath + EncryptXMLFileSuffix;
        }

        if (File.Exists(newPath))
        {
            byte[] data = File.ReadAllBytes(newPath);

            //解密
            if (SystemConfig.Instance.IsEncryptConfigFile)
            {
                DESCrypto.DecryptAsync(data, MyFileUtil.EncryptKey, (decryptedData) =>
                {
                    string result = System.Text.UTF8Encoding.UTF8.GetString(decryptedData);
                    callback(result);
                });
            }
            else
            {
                string result = System.Text.UTF8Encoding.UTF8.GetString(data);
                callback(result);
            }
        }
        else
        {
            callback(null);
        }
    }
示例#15
0
        public static string GetSoftData(int index)
        {
            DESCrypto des = new DESCrypto();

            try
            {
                FileStream   fs = new FileStream(filePath, FileMode.Open);
                BinaryReader sw = new BinaryReader(fs);
                //开始写入
                fs.Seek(index * blockSize * 2, SeekOrigin.Begin);
                byte[] rd = sw.ReadBytes(blockSize * 2);
                sw.Close();
                fs.Close();

                string strLen = Encoding.UTF8.GetString(rd, 0, lenlen);
                strLen = des.DecryptString(strLen, sKey_Len, sIV_Len);
                int    len    = int.Parse(strLen);
                string strDes = Encoding.UTF8.GetString(rd, blockSize, len);
                strDes = des.DecryptString(strDes, sKey, sIV);
                return(strDes);
            }
            catch
            {
                throw;
            }
        }
示例#16
0
    //解密Lua代码
    static public byte[] DecryptLuaCode(byte[] data)
    {
        if (SystemConfig.Instance.IsEncryptLuaCode)
        {
            return(DESCrypto.Decrypt(data, MyFileUtil.EncryptKey));
        }

        return(data);
    }
示例#17
0
        public void TestEncryptorAsync()
        {
            var    keyValue     = DESCrypto.CreatedKey();
            string encryptorStr = DESCrypto.EncryptorAsync(input, keyValue.Key, keyValue.Value).Result;

            Assert.IsNotNull(encryptorStr);
            Assert.IsTrue(encryptorStr.Length > 0);
            Console.WriteLine(encryptorStr);
        }
示例#18
0
 static public void EncryptLuaCode(string filePath)
 {
     if (SystemConfig.Instance.IsEncryptLuaCode)
     {
         byte[] data = File.ReadAllBytes(filePath);
         data = DESCrypto.Encrypt(data, MyFileUtil.EncryptKey);
         File.WriteAllBytes(filePath, data);
     }
 }
示例#19
0
    void LoadLib()
    {
        if (!bLoodLib)
        {
            bLoodLib = true;
        }
        else
        {
            return;
        }
        LoadSolutionLib();
        var enData = FileAccessManager.LoadBytes(FileName);

        if (enData != null)
        {
            //var sw = new System.Diagnostics.Stopwatch();
            //sw.Start();
            var deData = DESCrypto.Decrypt(enData, Number);
            //sw.Stop();
            deData = Utils.UnpackMemory(deData);
            //Debug.LogInfo("Decrypt time: " + sw.ElapsedMilliseconds);
            var ass = System.Reflection.Assembly.Load(deData); //动态库的名称
            //gameObject.AddComponent(ass.GetType("TestUI"));
            if (ass.GetType("MogoInitialize") != null)
            {
                gameObject.AddComponent(ass.GetType("MogoInitialize"));
            }
            else
            {
                Debug.LogError("---------------Reflection MogoInitialize Failed------------------------");
            }
            //gameObject.AddComponent(ass.GetType("TestUI"));

            if (Application.platform == RuntimePlatform.Android && SystemSwitch.UsePlatformSDK)
            {
                IsRunOnAndroid = true;
                if (ass.GetType("AndroidSdkManager") != null)
                {
                    gameObject.AddComponent(ass.GetType("AndroidSdkManager"));
                }
                else
                {
                    Debug.LogError("---------------Reflection AndroidSdkManager Failed------------------------");
                }
                //IsRunOnAndroid = false;
            }
            else
            {
                gameObject.AddComponent(ass.GetType("PlatformSdkManager"));
                IsRunOnAndroid = false;
            }
        }
        else
        {
            Debug.LogError("Missing MogoLib.");
        }
    }
示例#20
0
        public void TestCreateKey()
        {
            var keyValue = DESCrypto.CreatedKey();

            Assert.IsNotNull(keyValue);
            Assert.IsTrue(keyValue.Key.Length > 0);
            Assert.IsTrue(keyValue.Value.Length > 0);

            Console.WriteLine(keyValue.Key);
            Console.WriteLine(keyValue.Value);
        }
示例#21
0
 //解密Lua代码
 static private void DecryptLuaCodeAsync(byte[] data, Action <byte[]> callback)
 {
     if (SystemConfig.Instance.IsEncryptLuaCode)
     {
         DESCrypto.DecryptAsync(data, MyFileUtil.EncryptKey, callback);
     }
     else
     {
         callback(data);
     }
 }
示例#22
0
        static void Main(string[] args)
        {
            string plaintext = "abc"; string strmd5 = "900150983CD24FB0D6963F7D28E17F72"; string strdes = "Wr+MOY7jM8M=";

            //MD5
            var s1 = MD5Crypto.Encrypt(plaintext);

            Console.WriteLine("MD5 加密:{0} {1} {2}", s1 == strmd5, strmd5, s1); Console.WriteLine();

            //DES
            var s2 = DESCrypto.Encrypt(plaintext);

            Console.WriteLine("DES 加密:{0} {1} {2}", s2 == strdes, strdes, s2);

            var s3 = DESCrypto.Decrypt(s2);

            Console.WriteLine("DES 解密:{0} {1} {2}", s3 == plaintext, plaintext, s3); Console.WriteLine();

            //RSA
            string modulus = "nJDcBWNIV+DzZb8ZY5h4JJInVwVy5NvJ9hG0qH0TUM36j5DUFeUivBIdX+7fxwKIxPRkRyvwVjGjnMxna3Kq53Y5BLGpl84DvRqPGjxly2kAitbuHRIR5iiuza0rbA+ZPo/8kNrbRCYquaqnL1KIrDcIh7bZDWN6qY22+RVaVvs=";

            string publicExponent  = "AQAB";
            string privateExponent = "ZZTTPCerc2D/ar9vYKA3KzssjRh68CPuSFo6hasJEj9iVy2XfVE6lR2Hs4uP41YwmOEcAtVuTO5OAljYrO0sFpdYNrEthZG5UBkC2wH+SsXOAaTDb2YRCEsdxFA8MRqRQLux/9/Fef/oIk+od1sjC3WzBwMqvVHBO232u9V9suE=";

            //公钥加密
            var s4 = RSACrypto.EncryptByPublicExponent(plaintext, modulus, publicExponent);

            Console.WriteLine("RSA 公钥加密:" + s4);

            string p        = "y8v6G7Ap6jeTHILLAjQT0auvd9kRh91txQ4YkGf8ocijRbThKgAtWUrvNx27km6PEetWqw0VnA2YN53v6WCBMQ==";
            string q        = "xKuz+9vgOYZf9WvA0vU8byCmZd93mYrw+uAymUiT6jvG1MQ0vAQMW7wwoifJYIqWFNZo356R6g2OeOz8Edfv6w==";
            string dp       = "vqI3et721ljWC71tGMqOH3txz7IFbAn9PG9LGwmqj8uWrwXb+eXghb5KtkvhwcAZpLF3iNncdPViheP/H1degQ==";
            string dq       = "dZ+ruYo7hKwVYBbd8E2zo1MHsg4A3df3YFQObxa1QHYX6NCgKYLSUVswSws4qYC5WiUR/Aw+gJkzCKfT6mgXmQ==";
            string inverseQ = "Fohpu2QfkHBCy11L0MV88pX3+EszJWWSgXqsGUzxTx0c2WK33o5wZkjq0AEKgk19aOOJc0RoKwcw6vtRRux/+Q==";
            //私钥解密
            var s5  = RSACrypto.DecryptByPrivateExponent(s4, modulus, privateExponent, publicExponent, p, q, dp, dq, inverseQ);
            var s55 = RSACrypto.Decrypt(s4, modulus, privateExponent);

            Console.WriteLine("RSA 私钥解密 : {0} {1} {2}", s5 == plaintext, plaintext, s5);
            Console.WriteLine("RSA 私钥解密2: {0} {1} {2}", s55 == plaintext, plaintext, s55); Console.WriteLine();

            //私钥加密
            var s6 = RSACrypto.Encrypt(plaintext, modulus, privateExponent);

            Console.WriteLine("RSA 私钥加密:" + s6);

            //公钥解密
            var str6 = RSACrypto.Decrypt(s6, modulus, publicExponent);

            Console.WriteLine("RSA 公钥解密2:{0} {1} {2}", str6 == plaintext, plaintext, str6);

            Console.ReadKey();
        }
示例#23
0
    static void GenerateCopyProjectFileList()
    {
        string        dir      = CopyProjectTargetDir + "Assets/StreamingAssets/AssetBundles/" + ResourcesManager.GetPlatformDir() + "/";
        List <string> fileList = ResourcesManager.GenerateFileList(dir);
        string        xml      = ResourcesManager.GetFileListXMLString(fileList, dir);

        string filePath = CopyProjectTargetDir + "Assets/StreamingAssets/Config/" + ResourcesManager.FileListConfigFileName + MyFileUtil.EncryptXMLFileSuffix;

        File.WriteAllText(filePath, xml);
        DESCrypto.Encrypt(filePath, MyFileUtil.EncryptKey);

        Debug.Log("生成拷贝工程资源列表结束");
    }
示例#24
0
    public static string ReadDataInStreamingAssets(string filePath)
    {
        if (SystemConfig.Instance.IsEncryptConfigFile && filePath.EndsWith(EncryptXMLFileSuffix) == false)
        {
            filePath = filePath + EncryptXMLFileSuffix;
        }

        byte[] data = ReadDataInStreamingAssetsImp(filePath);
        //解密
        if (SystemConfig.Instance.IsEncryptConfigFile)
        {
            data = DESCrypto.Decrypt(data, MyFileUtil.EncryptKey);
        }
        return(System.Text.UTF8Encoding.UTF8.GetString(data));
    }
示例#25
0
        public void TestDecryptor()
        {
            var    keyValue     = DESCrypto.CreatedKey();
            string encryptorStr = DESCrypto.Encryptor(input, keyValue.Key, keyValue.Value);
            String decryptorStr = DESCrypto.Decryptor(encryptorStr, keyValue.Key, keyValue.Value);

            Assert.IsNotNull(encryptorStr);
            Assert.IsTrue(encryptorStr.Length > 0);
            Console.WriteLine(encryptorStr);

            Assert.IsNotNull(decryptorStr);
            Assert.IsTrue(decryptorStr.Length > 0);
            Console.WriteLine(decryptorStr);
            Assert.IsTrue(decryptorStr.Equals(input));
        }
示例#26
0
    void Start()
    {
        string content = "测试一下DES加密,hahhaha";
        string key     = "abcdefgh454365"; //key,iv 可以相同
        string iv      = "abcdefgh35345";

        byte[] contentBytes = Encoding.UTF8.GetBytes(content);
        byte[] encryBytes   = DESCrypto.Encrypt(contentBytes, key, iv);
        string encryStr     = Encoding.UTF8.GetString(encryBytes);

        Debug.Log(encryStr);

        byte[] decryBytes = DESCrypto.Decrypt(encryBytes, key, iv);
        string decryStr   = Encoding.UTF8.GetString(decryBytes);

        Debug.Log(decryStr);
    }
示例#27
0
        public void Test()
        {
            using (var desCrypto = new DESCrypto())
            {
                desCrypto.Initialize(new Dictionary <string, object>
                {
                    { "Key", "qxMfZpmQ1Rk=" },
                    { "IV", "XaX73vwx694=" }
                });

                var plainText = "SmartSql";

                var cipherText  = desCrypto.Encrypt(plainText);
                var decryptText = desCrypto.Decrypt(cipherText);
                Assert.Equal(plainText, decryptText);
            }
        }
示例#28
0
        public static bool CheckEncode_DES(VerifyMachineCode_DES vc)
        {
            lcyHashCal lcy = new lcyHashCal();
            DESCrypto  des = new DESCrypto();

            byte[] ID     = StringsFunction.strToHexByte(des.DecryptString(vc.ID, "wfMaCovf", "Machincd"), "");
            byte[] x      = lcy.HashCal(ID, lcyNum);
            byte[] Encode = StringsFunction.strToHexByte(des.DecryptString(vc.Encode, "wfMaCovf", "Machincd"), "");
            for (int i = 0; i < 8; i++)
            {
                if (x[i] != Encode[i])
                {
                    return(false);
                }
            }
            return(true);
        }
示例#29
0
    static void EncryptFile()
    {
        foreach (UnityEngine.Object obj in Selection.objects)
        {
            string path = AssetDatabase.GetAssetPath(obj.GetInstanceID());
            if (string.IsNullOrEmpty(path))
            {
                continue;
            }

            string filePath = Application.dataPath.Replace("Assets", "") + path;
            DESCrypto.Encrypt(filePath, MyFileUtil.EncryptKey);
        }

        AssetDatabase.Refresh();
        Debug.Log("文件加密结束");
    }
示例#30
0
        public void SetVerifyData_LicUpdateTime(DateTime value)
        {
            LicUpdateTime = value;
            DESCrypto  des = new DESCrypto();
            string     strDes = "", strLen;
            FileStream fs;

            fs     = new FileStream("Runinfo.mkt", FileMode.Open);
            strDes = des.EncryptString(LicUpdateTime.ToString("yyyy-MM-dd HH:mm:ss"), sKey, sIV_LicUpdateTime);
            BinaryWriter sw = new BinaryWriter(fs);

            //开始写入
            fs.Seek(400, SeekOrigin.Begin);
            strLen  = des.EncryptString(strDes.Length.ToString("d4"), sKey, sIV_Len);
            strLen += GenerateCheckCode(100 - lenlen);
            strDes += GenerateCheckCode(100 - strDes.Length);
            sw.Write(Encoding.UTF8.GetBytes(strLen + strDes));
            sw.Flush();
            //关闭流
            sw.Close();
            fs.Close();/**/
        }

        public void SetVerifyData_BINUpdateTime(DateTime value)
        {
            BINUpdateTime = value;
            DESCrypto  des = new DESCrypto();
            string     strDes = "", strLen;
            FileStream fs;

            fs     = new FileStream("Runinfo.mkt", FileMode.Open);
            strDes = des.EncryptString(BINUpdateTime.ToString("yyyy-MM-dd HH:mm:ss"), sKey, sIV_BINUpdateTime);
            BinaryWriter sw = new BinaryWriter(fs);

            //开始写入
            fs.Seek(600, SeekOrigin.Begin);
            strLen  = des.EncryptString(strDes.Length.ToString("d4"), sKey, sIV_Len);
            strLen += GenerateCheckCode(100 - lenlen);
            strDes += GenerateCheckCode(100 - strDes.Length);
            sw.Write(Encoding.UTF8.GetBytes(strLen + strDes));
            sw.Flush();
            //关闭流
            sw.Close();
            fs.Close();/**/
        }