11

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. What changes required to update this in existing code, I cannot update the application to newer framework.

Abdul
  • 1,416
  • 9
  • 26
  • 57

4 Answers4

24

I'm using VS 2008 with .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#):

public const SslProtocols _Tls12 = (SslProtocols)0x00000C00;
public const SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12;
ServicePointManager.SecurityProtocol = Tls12;

VB.net version:

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()  
D_Bester
  • 5,723
  • 5
  • 35
  • 77
3

just adding adding Your code in vb .net 3.5 version :

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

Yosep Tito
  • 737
  • 6
  • 7
2

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. 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.

Ian Bennett
  • 360
  • 3
  • 10
0

Add de following code:

System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

More details here

Jorge
  • 1