如何在.net 4.0下安装TLS1.2的支持

 

原始出处:www.cnblogs.com/Charltsing/p/Net4TLS12.html

作者QQ: 564955427

最近提交请求发生错误:不支持请求的协议,研究了一下TLS1.2,发现这玩意的支持和.Net环境的版本有关

 

//SecurityProtocolType.Tls1.0=0xC0; SecurityProtocolType.Tls1.1=0x300; SecurityProtocolType.Tls1.2=0xC00;
//.net 4.0/4.5默认值:SecurityProtocolType.Tls | SecurityProtocolType.Ssl3
//.net 4.6/4.7默认值:SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12
//https://support.microsoft.com/en-us/help/3069494/cannot-connect-to-a-server-by-using-the-servicepointmanager-or-sslstre
//SCH_USE_STRONG_CRYPTO 此标志将在.NET Framework 4.6中自动使用
//https://support.microsoft.com/en-us/help/3154518/support-for-tls-system-default-versions-included-in-the-net-framework 在Win7Sp1和.Net 3.5.1中,支持TLS1.2
ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3; //关闭ssl3
ServicePointManager.SecurityProtocol |= (SecurityProtocolType)0x300 | (SecurityProtocolType)0xc00; //增加1.1和1.2支持
//TLS1.2的结论是这样的:
//1、安装.Net3.5.1需要打个补丁,然后增加TLS1.2枚举
//2、安装.Net 4.0需要修改注册表,然后增加TLS1.2枚举
//3、安装.Net4.5之后,还需要增加TLS1.2枚举
//4、安装.Net4.6.1之后,默认支持TLS1.2

 

.net4下的注册表修改

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319]
"SchUseStrongCrypto"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319]
"SchUseStrongCrypto"=dword:00000001

 

posted @ 2018-10-15 21:11  Charltsing  阅读(2818)  评论(2编辑  收藏  举报