如何在 .Net 3.5 框架中实现安全协议 TLS 1.2 [英] How to implement Security Protocols TLS 1.2 in .Net 3.5 framework
本文介绍了如何在 .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屋!
查看全文