Below is the code which I want to use to create token from custom private key.. Where I am getting error for rsa.ImportRSAPrivateKey(privateKey, out _) method which is not supported in 2.0 .net framework
public string CreateToken(string _customerprivateKey, List<Claim> keypairs)
{
try
{
IdentityModelEventSource.ShowPII = true;
// var privateKey = privateKeybyteArr;
byte[] privateKey = Convert.FromBase64String(_customerprivateKey);
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048);
**rsa.ImportRSAPrivateKey(privateKey, out _); // not supported in 2.0 .net framework**
var signingCredentials = new SigningCredentials(
new RsaSecurityKey(rsa),
SecurityAlgorithms.RsaSha512)
{
CryptoProviderFactory = new CryptoProviderFactory { CacheSignatureProviders = false }
};
List<System.Security.Claims.Claim> _claims = new List<System.Security.Claims.Claim>();
foreach (var item in keypairs)
{
_claims.Add(new System.Security.Claims.Claim(item.Key, item.Value));
}
var jwt = new JwtSecurityToken(
claims: _claims,
signingCredentials: signingCredentials
);
string token = new JwtSecurityTokenHandler().WriteToken(jwt);
return token;
}
catch (Exception ex)
{
throw;
}
}