在代码的初始化中添加以下代码:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
在应用程序的配置文件中添加以下代码:
此配置仅允许使用 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 加密套件。
添加以下代码,以禁用 CBC 模式:
ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServicePointManager.SecurityProtocol |= SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11; ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; ServicePointManager.MaxServicePointIdleTime = 30000; ServicePointManager.DefaultConnectionLimit = 1000; CryptoConfig.AddAlgorithm(typeof(AesManaged), "AES");
以上代码将禁用 CBC 模式并开启 TLS 1.2。请注意,这样可能会导致其他安全风险,因此应认真评估所需的安全措施。