/// <summary> /// Decrypts a string /// </summary> /// <param name="s">string to decrypt</param> /// <param name="encryption">encryption to use</param> /// <returns></returns> public static string Decrypt(string s, Encryption encryption) { CryptoHelper c = new CryptoHelper(); switch (encryption) { case Encryption.none: return(s); case Encryption.AES: return(c.AesDecrypt(s, key)); case Encryption.base64: return(c.Base64Decrypt(s)); case Encryption.base64Reversed: return(c.Base64ReverseDecrypt(s)); case Encryption.Salsa20: return(c.salsa20Decrypt(s, key)); case Encryption.XOR: return(c.XorEncryptDecrypt(s, key)); default: return(s); } }
private async Task <string> Decrypt(HttpResponseMessage response, Aes aes) { var encryptedHex = await _sender.GetResponseString(response); var encryptedBytes = encryptedHex.HexToByte(); return(CryptoHelper.AesDecrypt(encryptedBytes, aes.Key, aes.IV)); }
void LoadHotFixAssembly() { appdomain = new AppDomain(); var dllAsset = Assets.LoadAssetAsync("HotUpdateScripts.bytes", typeof(TextAsset)); dllAsset.completed += delegate { if (dllAsset.error != null) { Log.PrintError(dllAsset.error); return; } var dll = (TextAsset)dllAsset.asset; byte[] original = dll.bytes; try { if (!Assets.runtimeMode) { original = CryptoHelper.AesDecrypt(original, "DevelopmentMode."); } else { original = CryptoHelper.AesDecrypt(original, Key); } } catch (Exception ex) { Log.PrintError("加载热更DLL失败,可能是解密密码不正确"); Log.PrintError("加载热更DLL错误:\n" + ex.Message); return; } fs = new MemoryStream(original); try { appdomain.LoadAssembly(fs, null, new PdbReaderProvider()); } catch (Exception e) { Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器"); Log.PrintError("加载热更DLL错误:\n" + e.Message); return; } InitializeILRuntime(); OnHotFixLoaded(); }; }
//public DbContextBase(DbContextOptions<DbContextBase> options) : base(options) //{ // this.dbConnection = Database.GetDbConnection(); // this.ConnectionString = dbConnection.ConnectionString; //} //private static MethodInfo applyConcreteMethod; static DbContextBase() { //if (applyConcreteMethod == null) //{ // //applyConcreteMethod = typeof(ModelBuilder).GetMethods(BindingFlags.Instance | BindingFlags.Public).Where // // (p => p.Name == "ApplyConfiguration" && p.GetParameters().FirstOrDefault().ParameterType.GetGenericTypeDefinition() == typeof(IEntityTypeConfiguration<>)).FirstOrDefault(); // applyConcreteMethod = typeof(ModelBuilder).GetMethods().Single(p => p.Name == "ApplyConfiguration" && p.GetParameters().SingleOrDefault().ParameterType.GetGenericTypeDefinition() == typeof(IEntityTypeConfiguration<>)); //} if (connectionString.IsNullOrWhiteSpace()) { FileInfo fileInfo = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Config\conn.json")); using (var s = fileInfo.OpenText()) { var json = JsonConvert.DeserializeObject <dynamic>(s.ReadToEnd()); connectionString = CryptoHelper.AesDecrypt((string)(json.DB)); } } }
public async Task SimulateSendSecretMessage() { await Scatter.Connect(); var fromKey = await Scatter.GetPublicKey(Scatter.Blockchains.EOSIO); var toKey = await Scatter.GetPublicKey(Scatter.Blockchains.EOSIO); var r = new Random(); var nonce = (UInt64)r.Next(); var text = "Hello crypto secret message!"; var encryptionKeyA = await Scatter.GetEncryptionKey(fromKey, toKey, nonce); var encryptionKeyABytes = UtilsHelper.HexStringToByteArray(encryptionKeyA); Console.WriteLine("FromKey: {0}", fromKey); Console.WriteLine("ToKey: {0}", toKey); Console.WriteLine("Original: {0}", text); var encrypted = CryptoHelper.AesEncrypt(encryptionKeyABytes, text); Console.WriteLine("Encrypted: {0}", Encoding.UTF8.GetString(encrypted)); //...Send over the wire... var encryptionKeyB = await Scatter.GetEncryptionKey(toKey, fromKey, nonce); var encryptionKeyBBytes = UtilsHelper.HexStringToByteArray(encryptionKeyB); Console.WriteLine("A_PVT_KEY + B_PUB_KEY: {0}", encryptionKeyA); Console.WriteLine("B_PVT_KEY + A_PUB_KEY: {0}", encryptionKeyB); Assert.IsTrue(encryptionKeyA == encryptionKeyB); var roundtrip = CryptoHelper.AesDecrypt(encryptionKeyBBytes, encrypted); Console.WriteLine("Round Trip: {0}", roundtrip); }
public async Task OneWayEncryptDecrypt() { await Scatter.Connect(); var fromKey = await Scatter.GetPublicKey(Scatter.Blockchains.EOSIO); var toKey = await Scatter.GetPublicKey(Scatter.Blockchains.EOSIO); var r = new Random(); var encryptionKey = await Scatter.GetEncryptionKey(fromKey, toKey, (UInt64)r.Next()); var encryptionKeyBytes = UtilsHelper.HexStringToByteArray(encryptionKey); string text = "Hello crypto secret message!"; var encrypted = CryptoHelper.AesEncrypt(encryptionKeyBytes, text); var roundtrip = CryptoHelper.AesDecrypt(encryptionKeyBytes, encrypted); Console.WriteLine("FromKey: {0}", fromKey); Console.WriteLine("ToKey: {0}", toKey); Console.WriteLine("Original: {0}", text); Console.WriteLine("Encrypted: {0}", Encoding.UTF8.GetString(encrypted)); Console.WriteLine("Round Trip: {0}", roundtrip); }
void LoadHotFixAssembly() { appdomain = new AppDomain(); pdb = null; //编译模式 if (!Assets.runtimeMode) { if (File.Exists(dllPath)) { fs = new MemoryStream(DLLMgr.FileToByte(dllPath)); } else { Log.PrintError("DLL文件不存在"); return; } //查看是否有PDB文件 if (File.Exists(pdbPath) && UsePdb && (File.GetLastWriteTime(dllPath) - File.GetLastWriteTime(pdbPath)).Seconds < 30) { pdb = new MemoryStream(DLLMgr.FileToByte(pdbPath)); } } else//解密加载 { var dllAsset = Assets.LoadAsset("HotUpdateScripts.bytes", typeof(TextAsset)); if (dllAsset.error != null) { Log.PrintError(dllAsset.error); return; } var dll = (TextAsset)dllAsset.asset; try { var original = CryptoHelper.AesDecrypt(dll.bytes, Key); fs = new MemoryStream(original); } catch (Exception ex) { Log.PrintError("加载热更DLL失败,可能是解密密码不正确"); Log.PrintError("加载热更DLL错误:\n" + ex.Message); return; } } try { appdomain.LoadAssembly(fs, pdb, new PdbReaderProvider()); } catch (Exception e) { if (!UsePdb) { Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器"); Log.PrintError("加载热更DLL错误:\n" + e.Message); return; } Log.PrintError("PDB不可用,可能是DLL和PDB版本不一致,可能DLL是Release,如果是Release出包,请取消UsePdb选项,本次已跳过使用PDB"); UsePdb = false; LoadHotFixAssembly(); } InitILrt.InitializeILRuntime(appdomain); OnHotFixLoaded(); }
void LoadHotFixAssembly() { appdomain = new AppDomain(); if (!Assets.runtimeMode) { DLLMgr.MakeBytes(); } var dllAsset = Assets.LoadAsset("HotUpdateScripts.bytes", typeof(TextAsset)); if (dllAsset.error != null) { Log.PrintError(dllAsset.error); return; } var dll = (TextAsset)dllAsset.asset; byte[] original = dll.bytes; try { if (!Assets.runtimeMode) { original = CryptoHelper.AesDecrypt(original, "DevelopmentMode."); } else { original = CryptoHelper.AesDecrypt(original, Key); } } catch (Exception ex) { Log.PrintError("加载热更DLL失败,可能是解密密码不正确"); Log.PrintError("加载热更DLL错误:\n" + ex.Message); return; } fs = new MemoryStream(original); MemoryStream pdb = null; #if UNITY_EDITOR if (File.Exists("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb")) { try { pdb = new MemoryStream(AssetDatabase.LoadAssetAtPath <TextAsset>("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb").bytes); } catch { } } #endif try { appdomain.LoadAssembly(fs, pdb, new PdbReaderProvider()); } catch (Exception e) { Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器"); Log.PrintError("加载热更DLL错误:\n" + e.Message); return; } InitILrt.InitializeILRuntime(appdomain); OnHotFixLoaded(); }
void LoadHotFixAssembly() { appdomain = new AppDomain(); pdb = null; //编译模式 if (!Assets.runtimeMode) { if (File.Exists("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.dll")) { fs = new MemoryStream(DLLMgr.FileToByte("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.dll")); } else { Log.PrintWarning("DLL文件不存在"); return; } //查看是否有PDB文件 if (File.Exists("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb")) { pdb = new MemoryStream(DLLMgr.FileToByte("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb")); } } else//解密加载 { var dllAsset = Assets.LoadAsset("HotUpdateScripts.bytes", typeof(TextAsset)); if (dllAsset.error != null) { Log.PrintError(dllAsset.error); return; } var dll = (TextAsset)dllAsset.asset; try { var original = CryptoHelper.AesDecrypt(dll.bytes, Key); fs = new MemoryStream(original); } catch (Exception ex) { Log.PrintError("加载热更DLL失败,可能是解密密码不正确"); Log.PrintError("加载热更DLL错误:\n" + ex.Message); return; } } try { appdomain.LoadAssembly(fs, pdb, new PdbReaderProvider()); } catch (Exception e) { Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器"); Log.PrintError("加载热更DLL错误:\n" + e.Message); return; } InitILrt.InitializeILRuntime(appdomain); OnHotFixLoaded(); }