public IAsymmetricCryptoProvider CreateAsymmetric(SdmAsymmetricAlgorithm algorithm) { switch (algorithm) { case SdmAsymmetricAlgorithm.RSA: return(new RSACryptoProviderNET()); case SdmAsymmetricAlgorithm.RSACrypto: return(new RSACryptoProviderCryptoNET()); default: throw new NotSupportedException(algorithm + " is not supported."); } }
private void Load(bool saveDefault) { IniFile cfg; try { cfg = new IniFile(ConfigFileName, Encoding.UTF8); } catch (FileNotFoundException) { if (saveDefault) { Save(); } return; } catch (IOException) { return; } string tmp = null; if (cfg.ContainsSection("socket")) { cfg.TryGetBool("socket", "ipv6", ref UseIPv6); cfg.TryGetInt32("socket", "send_timeout", ref SocketSendTimeout); cfg.TryGetInt32("socket", "send_buffer_size", ref SocketSendBufferSize); cfg.TryGetInt32("socket", "recv_buffer_size", ref SocketReceiveBufferSize); cfg.TryGetInt32("socket", "backlog", ref SocketBacklog); } if (cfg.ContainsSection("server")) { if (cfg.TryGetString("server", "protocol", ref tmp)) { ProtocolId p; if (Enum.TryParse(tmp, true, out p)) { Protocol = p; } } if (cfg.TryGetString("server", "address", ref tmp)) { var af = UseIPv6 ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork; try { Address = NetUtil.GetHostByName(tmp, af); } catch { } } int port = 0; if (cfg.TryGetInt32("server", "port", ref port)) { if (0 <= port && port <= ushort.MaxValue) { Port = (ushort)port; } } } if (cfg.ContainsSection("security")) { if (cfg.TryGetString("security", "sym_algorithm", ref tmp)) { SdmSymmetricAlgorithm sa; if (Enum.TryParse(tmp, true, out sa)) { SymAlgorithm = sa; } } if (cfg.TryGetString("security", "asym_algorithm", ref tmp)) { SdmAsymmetricAlgorithm aa; if (Enum.TryParse(tmp, true, out aa)) { AsymAlgorithm = aa; } } cfg.TryGetInt32("security", "sym_key_size", ref SymAlgorithmKeySize); cfg.TryGetInt32("security", "asym_key_size", ref AsymAlgorithmKeySize); } if (cfg.ContainsSection("misc")) { cfg.TryGetInt32("misc", "update_sleep", ref UpdateSleep); } }
private void Load() { IniFile cfg; try { cfg = new IniFile(ConfigFileName, Encoding.UTF8); } catch (IOException) { return; } string tmp = null; if (cfg.ContainsSection("socket")) { cfg.TryGetBool("socket", "ipv6", ref UseIPv6); cfg.TryGetInt32("socket", "send_timeout", ref SocketSendTimeout); cfg.TryGetInt32("socket", "send_buffer_size", ref SocketSendBufferSize); cfg.TryGetInt32("socket", "recv_buffer_size", ref SocketReceiveBufferSize); } if (cfg.ContainsSection("client")) { if (cfg.TryGetString("client", "protocol", ref tmp)) { ProtocolId p; if (Enum.TryParse(tmp, true, out p)) { Protocol = p; } } if (cfg.TryGetString("client", "host", ref tmp)) { Host = tmp; } int port = 0; if (cfg.TryGetInt32("client", "port", ref port)) { if (0 <= port && port <= ushort.MaxValue) { Port = (ushort)port; } } if (cfg.TryGetString("client", "login", ref tmp)) { Login = tmp; } if (cfg.TryGetString("client", "password", ref tmp) && tmp != "") { Password = Decrypt(tmp); } cfg.TryGetBool("client", "remember", ref Remember); } if (cfg.ContainsSection("security")) { if (cfg.TryGetString("security", "sym_algorithm", ref tmp)) { SdmSymmetricAlgorithm sa; if (Enum.TryParse(tmp, true, out sa)) { SymAlgorithm = sa; } } if (cfg.TryGetString("security", "asym_algorithm", ref tmp)) { SdmAsymmetricAlgorithm aa; if (Enum.TryParse(tmp, true, out aa)) { AsymAlgorithm = aa; } } } if (cfg.ContainsSection("misc")) { cfg.TryGetInt32("misc", "update_sleep", ref UpdateSleep); } }