我尝试按照these instructions使用WIF创建SAML2令牌。
说明说
要向SecurityTokenDescriptor提供签名凭据,您必须 首先获得对签名证书的引用 X509Certificate2实例。从这里你可以创建一个 SecurityKeyIdentifier并生成一个SigningCredentials实例
提供以下代码:
X509Certificate2 signingCert = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, "CN=busta-rpsts.com ");
SecurityKeyIdentifier ski = new SecurityKeyIdentifier(new SecurityKeyIdentifierClause[] { new X509SecurityToken(signingCert).CreateKeyIdentifierClause<X509SubjectKeyIdentifierClause>() });
X509SigningCredentials signingCreds = new X509SigningCredentials(signingCert, ski);
descriptor.SigningCredentials = signingCreds;
我尝试使用包含主题密钥标识符的 makecert 制作测试证书,但是当我运行通过上述代码制作的任何证书时,我得到以下系统.NotSupportedException :
&#39; X509SecurityToken&#39;不支持&#39; X509SubjectKeyIdentifierClause&#39; 创建
调用此行时会发生这种情况:
new X509SecurityToken(signingCert).CreateKeyIdentifierClause<X509SubjectKeyIdentifierClause>()
现在我知道说明了......
注意:使用makecert.exe创建的证书不包含主题 密钥标识符因此不能以这种方式使用。你应该 使用Windows Server生成证书或购买证书 来自Verisign或同等的提供商。
...但我已经使用了论据 -eku 2.5.29.14 ,我希望能解决这个问题,我认为这张照片表明我已经完成了正确?
任何人都可以告诉我如何创建一个测试证书,我可以用它来使这段代码正常工作,或指向正确的方向吗?我也不确定它们的含义&#34;您应该使用Windows Server生成证书。&#34;这是否意味着creating a CSR?
提前致谢:)
答案 0 :(得分:1)
恕我直言,最好模拟真实场景,以便创建一个CA,它将发出用于生成SAML令牌的证书。您将了解有关PKI和证书的更多信息,解决开发时间中的问题,而不是生产时间。但从技术上讲,不需要这样做。
所以需要做的事情:
X509Certificate2 signingCert = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, "CN=busta-rpsts.com ");
会起作用......可能。如果没有,您将不得不修改私钥权限(mmc),以便您的帐户可以使用本地计算机个人存储中的私钥。