[英]How to implement Security Protocols TLS 1.2 in .Net 3.5 framework
As Paypal updated their response, I need to update security protocols TLS to v1.2 in my existing application which is on .NET 3.5 framework. 随着Paypal更新他们的响应,我需要在.NET 3.5框架上的现有应用程序中将安全协议TLS更新到v1.2。 What changes required to update this in existing code, I cannot update the application to newer framework.
在现有代码中更新此更改所需的更改,我无法将应用程序更新到更新的框架。
I'm using VS 2008 with .net 3.5.30729.4926. 我正在使用VS 2008与.net 3.5.30729.4926。 All I had to do was:
我所要做的就是:
Add imports: 添加进口:
Imports System.Security.Authentication
Imports System.Net
Add this to my code (C#): 将其添加到我的代码(C#):
public const SslProtocols _Tls12 = (SslProtocols)0x00000C00;
public const SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12;
ServicePointManager.SecurityProtocol = Tls12;
VB.net version: VB.net版本:
Const _Tls12 As SslProtocols = DirectCast(&HC00, SslProtocols)
Const Tls12 As SecurityProtocolType = DirectCast(_Tls12, SecurityProtocolType)
ServicePointManager.SecurityProtocol = Tls12
Dim wbrq As HttpWebRequest
Dim wbrs As HttpWebResponse
Dim sw As StreamWriter
Dim sr As StreamReader
Dim strResult As String
'Create a new HttpWebRequest object.
wbrq = WebRequest.Create(strURL)
wbrq.Method = "POST"
wbrq.ContentLength = DataString.Length
wbrq.ContentType = "application/x-www-form-urlencoded"
'upload data
sw = New StreamWriter(wbrq.GetRequestStream)
sw.Write(DataString)
sw.Close()
'get response
wbrs = wbrq.GetResponse
sr = New StreamReader(wbrs.GetResponseStream)
strResult = sr.ReadToEnd.Trim
sr.Close()
just adding adding Your code in vb .net 3.5 version : 只需在vb .net 3.5版本中添加您的代码:
ServicePointManager.SecurityProtocol = DirectCast(3072, SecurityProtocolType)
then Your code become : 那么你的代码变成:
ServicePointManager.SecurityProtocol = DirectCast(3072, SecurityProtocolType)
Dim wbrq As HttpWebRequest
Dim wbrs As HttpWebResponse
Dim sw As StreamWriter
Dim sr As StreamReader
Dim strResult As String
'Create a new HttpWebRequest object.
wbrq = WebRequest.Create(strURL)
wbrq.Method = "POST"
wbrq.ContentLength = DataString.Length
wbrq.ContentType = "application/x-www-form-urlencoded"
.............
hope this help 希望这个帮助
If you are on NET 3.5.1 you have an option of applying a rollup hotfix and apply a registry edit to tell .NET to use the system default. 如果您使用的是.NET 3.5.1,则可以选择应用汇总修补程序并应用注册表编辑以告知.NET使用系统默认值。 More details here
更多细节在这里
Failing that you need to be using .NET 4.5 for TLS 1.2 & 1.1 support and on Windows Server 2008 R2 at a minimum. 如果您未能使用.NET 4.5 for TLS 1.2和1.1支持,并且至少需要在Windows Server 2008 R2上使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.