其他分享
首页 > 其他分享> > ServicePointManager.SecurityProtocol

ServicePointManager.SecurityProtocol

作者:互联网

.NET40兼容,默认框架越新集成的TLS协议版本就越高,最新最安全的是TLS1.3版本。

        [SecurityCritical]
        [SecuritySafeCritical]
        private static void InitialSecurityProtocol()
        {
            try
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                              | SecurityProtocolType.Tls
                                              | (SecurityProtocolType)0x300 // Tls11
                                              | (SecurityProtocolType)0xC00 // Tls12
                                              | (SecurityProtocolType)0x3000; // Tls13
            }
            catch (Exception)
            {
                try
                {
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                                  | SecurityProtocolType.Tls
                                                  | (SecurityProtocolType)0x300 // Tls11
                                                  | (SecurityProtocolType)0xC00; // Tls12
                }
                catch (Exception)
                {
                    try
                    {
                        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                                        | SecurityProtocolType.Tls
                                                        | (SecurityProtocolType)0x300; // Tls11
                    }
                    catch (Exception)
                    {
                        try
                        {
                            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                                            | SecurityProtocolType.Tls;
                        }
                        catch (Exception) { }
                    }
                }
            }
        }

标签:Ssl3,Exception,ServicePointManager,catch,SecurityProtocol,SecurityProtocolType
来源: https://blog.csdn.net/liulilittle/article/details/121021785