如何在.Net 3.5框架中实现安全协议TLS 1.2 [英] How to implement Security Protocols TLS 1.2 in .Net 3.5 framework

查看:1041
本文介绍了如何在.Net 3.5框架中实现安全协议TLS 1.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Paypal更新他们的响应时,我需要在.NET 3.5框架上的现有应用程序中将安全协议TLS更新为v1.2. 要在现有代码中更新此内容需要进行哪些更改,我无法将应用程序更新到较新的框架.

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.

推荐答案

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

I'm using VS 2008 with .net 3.5.30729.4926. All I had to do was:

添加导入:

Imports System.Security.Authentication
Imports System.Net

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

Add this to my code (C#):

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

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()  

这篇关于如何在.Net 3.5框架中实现安全协议TLS 1.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆