/// <summary> /// Initializes user connections listener. /// </summary> /// <param name="localEndPoint">Local ip endpoint.</param> /// <param name="backlog">Backlog.</param> /// <param name="enableFirewall">True, if firewall must be enabled, otherwise false.</param> internal static void Initialize(IPEndPoint localEndPoint, int backlog, bool enableFirewall) { m_LocalEndPoint = localEndPoint; m_Backlog = backlog; m_EnableFirewall = enableFirewall; RSAManaged rsa = new RSAManaged(1024); PrivateKey = rsa.ExportParameters(true); PublicKey = rsa.ExportParameters(false); ScrambledKeysPair = new ScrambledKeyPair(ref PrivateKey, ref PublicKey); rsa = null; Enable(); }
public override RSAParameters ExportParameters(bool includePrivateParameters) { if ((includePrivateParameters) && (!privateKeyExportable)) { throw new CryptographicException("cannot export private key"); } return(rsa.ExportParameters(includePrivateParameters)); }
private void ImportPrivateKey(X509Certificate certificate, CspParameters cspParams) { RSACryptoServiceProvider rsaCsp = certificate.RSA as RSACryptoServiceProvider; if (rsaCsp != null) { if (rsaCsp.PublicOnly) { return; } RSACryptoServiceProvider csp = new RSACryptoServiceProvider(cspParams); csp.ImportParameters(rsaCsp.ExportParameters(true)); csp.PersistKeyInCsp = true; return; } RSAManaged rsaMng = certificate.RSA as RSAManaged; if (rsaMng != null) { if (rsaMng.PublicOnly) { return; } RSACryptoServiceProvider csp = new RSACryptoServiceProvider(cspParams); csp.ImportParameters(rsaMng.ExportParameters(true)); csp.PersistKeyInCsp = true; return; } DSACryptoServiceProvider dsaCsp = certificate.DSA as DSACryptoServiceProvider; if (dsaCsp != null) { if (dsaCsp.PublicOnly) { return; } DSACryptoServiceProvider csp = new DSACryptoServiceProvider(cspParams); csp.ImportParameters(dsaCsp.ExportParameters(true)); csp.PersistKeyInCsp = true; } }