3

I would like to know how Firebase key could be imported to c# and being used as SingingCredintials for JWT?

private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAAS\n-----END PRIVATE KEY-----\n",

I have tried the following so far, but it bring wrong signing algorithm not RS256

RsaPrivateCrtKeyParameters key;
            using (StringReader sr = new StringReader(fbPrivateKey)) //here used StringReader
            {
                PemReader pr = new PemReader(sr);
                key = (RsaPrivateCrtKeyParameters)pr.ReadObject(); //no more keyPair because I just have the privKey only
            }
            RSAParameters rsaParams = DotNetUtilities.ToRSAParameters(key);
            RSACryptoServiceProvider rsa;
            rsa = new RSACryptoServiceProvider();
            rsa.ImportParameters(rsaParams);

var nRsa = PemKeyUtils.GetRSAProviderFromPemFile(fbPrivateKey);

            Microsoft.IdentityModel.Tokens.RsaSecurityKey _signingKey = new Microsoft.IdentityModel.Tokens.RsaSecurityKey(nRsa);
            Microsoft.IdentityModel.Tokens.SigningCredentials signingCredentials =
            new Microsoft.IdentityModel.Tokens.SigningCredentials(_signingKey, Microsoft.IdentityModel.Tokens.SecurityAlgorithms.RsaSha256);

Also I have tried this with no success

string jwt = string.Empty;
    RsaPrivateCrtKeyParameters keyPair;

    using (StringReader sr = new StringReader(fbPrivateKey)) //here used StringReader
    {
        PemReader pr = new PemReader(sr);
        keyPair = (RsaPrivateCrtKeyParameters)pr.ReadObject(); //no more keyPair because I just have the privKey only
    }

RSAParameters rsaParams = DotNetUtilities.ToRSAParameters((RsaPrivateCrtKeyParameters)keyPair);

It bring the keyid null and the algorithim rsa-sha1, which is supposed to be rsa256.

AL.
  • 36,815
  • 10
  • 142
  • 281
Madi
  • 146
  • 1
  • 3
  • 13
  • View https://stackoverflow.com/questions/38188122/firebase-3-creating-a-custom-authentication-token-using-net-and-c-sharp – Fabricio Jan 17 '18 at 13:09

0 Answers0