Example #1
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)));
        }
Example #2
0
    //解密Lua代码
    static public byte[] DecryptLuaCode(byte[] data)
    {
        if (SystemConfig.Instance.IsEncryptLuaCode)
        {
            return(DESCrypto.Decrypt(data, MyFileUtil.EncryptKey));
        }

        return(data);
    }
Example #3
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.");
        }
    }
Example #4
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();
        }
Example #5
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));
    }
Example #6
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);
    }
Example #7
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);
            }
        }
Example #8
0
    static void DecryptFile()
    {
        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.Decrypt(filePath, MyFileUtil.EncryptKey);
        }

        AssetDatabase.Refresh();
        Debug.Log("文件解密结束");
    }
Example #9
0
        private static string DecryptAndCheckSign(string txt)
        {
            int    i   = txt.IndexOf(';');
            string num = txt.Substring(0, i);
            int    len;

            if (!int.TryParse(num, out len) || len <= 0)
            {
                return(null);
            }
            string orgin = DESCrypto.Decrypt(txt.Substring(i + 1, len));
            string sign  = txt.Substring(i + 1 + len, txt.Length - i - 1 - len);

            if (sign == Md5Encrypt(orgin + PRIVATE_KEY))
            {
                return(orgin);
            }
            return(null);
        }
Example #10
0
    void LoadSolutionLib()
    {
        var index   = 0;
        var resName = FileName + index;

        while (FileAccessManager.IsFileExist(resName))
        {
            Debug.Log("load: " + resName);
            var enData = FileAccessManager.LoadBytes(resName);
            if (enData != null)
            {
                var deData = DESCrypto.Decrypt(enData, Number);
                deData = Utils.UnpackMemory(deData);
                System.Reflection.Assembly.Load(deData);
            }
            index++;
            resName = FileName + index;
        }
    }
Example #11
0
    public static string ReadDataInCacheDir(string filePath)
    {
        string newPath = OuterDir + "/" + 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)
            {
                data = DESCrypto.Decrypt(data, MyFileUtil.EncryptKey);
            }

            return(System.Text.UTF8Encoding.UTF8.GetString(data));
        }

        return(null);
    }
Example #12
0
 public static byte[] DecryptData(byte[] data)
 {
     data = DESCrypto.Decrypt(data, EncryptKey);
     return(data);
 }