certificate - 为自定义 Azure B2C 邀请策略调用 FromSigningCredentials 时,证书不是 RSA 证书
问题描述
我正在为 Azure B2C 尝试此自定义邀请策略代码:
https://github.com/azure-ad-b2c/samples/tree/master/policies/invite#signup-with-email-invitation
我按照分步指南创建了证书,但是当代码遇到方法时FromSigningCredentials
,它会抛出异常Certificate is not an RSA certificate.
。
这是代码:
public static JwksKeyModel FromSigningCredentials(X509SigningCredentials signingCredentials)
{
X509Certificate2 certificate = signingCredentials.Certificate;
// JWK cert data must be base64 (not base64url) encoded
string certData = Convert.ToBase64String(certificate.Export(X509ContentType.Cert));
// JWK thumbprints must be base64url encoded (no padding or special chars)
string thumbprint = Base64UrlEncoder.Encode(certificate.GetCertHash());
// JWK must have the modulus and exponent explicitly defined
RSACng rsa = certificate.PublicKey.Key as RSACng;
if (rsa == null)
{
throw new Exception("Certificate is not an RSA certificate.");
}
.
.
.
证书已加载,但在执行以下行之后:
RSACng rsa = certificate.PublicKey.Key as RSACng;
rsa
一片空白。
这发生在本地和 Azure 网站上。
我在这里想念什么?
解决方案
经过一番研究,我刚刚发现了以下问题@GitHub:https ://github.com/dotnet/corefx/issues/26682
用户bartonjs 告诉以下内容:
任何人都不应该调用 cert.PublicKey.Key;您应该改用 cert.GetRSAPublicKey()。
我将问题中的那一行替换为:
// JWK must have the modulus and exponent explicitly defined
RSACng rsa = certificate.GetRSAPublicKey() as RSACng;
现在我可以走了...
推荐阅读
- json - 将 Json 字符串分配给单个键
- java - log4j2 自定义过滤器中的问题
- c - 对多个相同数组使用结构——在浮点数中查找平均值
- javascript - JavaScript“使用严格”在 Chrome 代码片段/DevTools Sources 面板中不一致地工作
- python - 通过循环 CSV python 的标题列在 YouTube API 上运行多个查询
- validation - BadMethodCallException 方法 [验证] 不存在
- node.js - APP Engine Google Cloud Storage - 下载文件时出现错误 500
- reactjs - 如何使用 Microsoft Authentication Library (MSAL) 在 Cypress 中测试登录
- angular - 如何从firebase获取嵌套的json数据?
- javascript - JavaScript 发布并等待响应 JSON