Files
webRtc/Assets/Script/SelfSignedCertHandler.cs
2026-05-19 22:40:52 +08:00

28 lines
853 B
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using UnityEngine.Networking;
using System.IO;
using System.Security.Cryptography.X509Certificates;
/// <summary>
/// 信任指定自签名证书
/// </summary>
public class SelfSignedCertHandler : CertificateHandler
{
// 受信任的证书数据(从 StreamingAssets 加载)
private X509Certificate2 _trustedCert;
public SelfSignedCertHandler(byte[] certData)
{
_trustedCert = new X509Certificate2(certData);
}
protected override bool ValidateCertificate(byte[] certificateData)
{
// 方法1严格匹配整本证书推荐
var remoteCert = new X509Certificate2(certificateData);
return remoteCert.Thumbprint == _trustedCert.Thumbprint;
// 方法2宽松模式 - 只要证书能解析就信任(调试用,危险)
// return true;
}
}