关于我的企业项目(仅限内联网),我遇到了一个使用.net验证证书的问题 System.Security.Cryptography.X509Certificates
第1步:创建根证书
使用makecert创建一个根证书并将其安装到受信任的根证书颁发机构
makecert -r -pe -n "CN=Test Labs (CA)" -ss CA -sr CurrentUser -a sha256 -cy authority -sky signature -sv TestLabCA.pvk TestLabCA.cer
pvk2pfx -pvk TestLabCA.pvk -spc TestLabCA.cer -pfx TestLabCA.pfx
Run Code Online (Sandbox Code Playgroud)
步骤2:创建证书并使用根证书对其进行签名
使用makecert创建证书,根证书签名,并将其安装到受信任的发布者
makecert -pe -n "CN=Test Labs (SPC)" -a sha256 -cy end -sky signature -ic TestLabCA.cer -iv TestLabCA.pvk -sv TestLabSPC.pvk TestLabSPC.cer
pvk2pfx -pvk TestLabSPC.pvk -spc TestLabSPC.cer -pfx TestLabSPC.pfx
Run Code Online (Sandbox Code Playgroud)
第3步:在代码中验证
这是验证证书的C#代码示例:
X509Certificate2 rootCertificate = new X509Certificate2("TestLabCA.cer");
X509Certificate2 certificate = new X509Certificate2("TestLabSPC.cer"); …Run Code Online (Sandbox Code Playgroud)