Сертификат не является сертификатом RSA при вызове FromSigningCredentials для пользовательской политики приглашения Azure B2C - PullRequest
0 голосов
/ 11 июля 2019

Я пытаюсь использовать этот пользовательский код политики приглашения для 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 равно нулю.

enter image description here

Это происходит локально и на веб-сайте Azure.

Что мне здесь не хватает?

1 Ответ

1 голос
/ 11 июля 2019

После некоторых исследований я обнаружил следующую проблему @ 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;

Теперь мне пора ...

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...