自分自身で提供する非対称キーを使用して.Net 4.5でJWTトークンを生成したいのですが、System.IdentityModel.Tokens.Jwt、version 4.0でいくつかの問題が発生しています.3。RsaSecurityKeyは引数としてRSAParametersを使用しません
私は2048キーを作成することをお勧めします。 RSA.Create()コンストラクタは1024個のキーを作成します。次のコード切り取り領域がそのhttps://stackoverflow.com/a/38233644注由来
using (RSACryptoServiceProvider provider = new RSACryptoServiceProvider(2048))
{
var publicPrivate = provider.ToXmlString(true);
var publicKeyOnly = provider.ToXmlString(false);
var stuff = provider.ExportParameters(true);
signingCredentials = new SigningCredentials(new RsaSecurityKey(RSA.Create()), SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest); //no idea how to pull the key out of here.
}
多くの例では、1つはRsaSecurityKeyコンストラクタにRSAParametersをドロップすることができ、今では、(任意の文字列パラメータを用いて)RSA.Create()コンストラクタをとり、この例ではRSAParametersは、私のバージョンではできないRsaSecurityKeyコンストラクタにうまく行きます。私はRSA.Createを使用することに制限されています。
// NOTE: Replace this with your actual RSA public/private keypair!
var provider = new RSACryptoServiceProvider(2048);
var parameters = provider.ExportParameters(true);
// Build the credentials used to sign the JWT
var signingKey = new RsaSecurityKey(parameters); //not an option for me, unfortunately
この要素の1つは、4.0.3ではRsaSecurityKeyのパラメータを使用しないことです。プロバイダを使用します。 varプロバイダ=新しいRSACryptoService(2048); var signingKey =新しいRsaSecurityKey(プロバイダ)。 次のリンクにあります。 https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/477 – user7101139