如何在.Net 3.5框架中实现安全协议TLS 1.2

tri*_*ati 11 .net c# asp.net paypal tls1.2

随着Paypal更新他们的响应,我需要在.NET 3.5框架上的现有应用程序中将安全协议TLS更新到v1.2.在现有代码中更新此更改所需的更改,我无法将应用程序更新到更新的框架.

D_B*_*ter 16

我正在使用VS 2008与.net 3.5.30729.4926.我所要做的就是:

添加进口:

Imports System.Security.Authentication
Imports System.Net
Run Code Online (Sandbox Code Playgroud)

将其添加到我的代码(C#):

public const SslProtocols _Tls12 = (SslProtocols)0x00000C00;
public const SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12;
ServicePointManager.SecurityProtocol = Tls12;
Run Code Online (Sandbox Code Playgroud)

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()  
Run Code Online (Sandbox Code Playgroud)


小智 2

如果您使用的是 NET 3.5.1,您可以选择应用汇总修补程序并应用注册表编辑来告诉 .NET 使用系统默认值。 更多详情请点击这里

否则,您至少需要在 Windows Server 2008 R2 上使用 .NET 4.5 来支持 TLS 1.2 和 1.1。