0
아래 제안 사항을 시도했지만 SecurityAlgorithms.HmacSha256Signature에서 작업 중입니다.IDX10634 : SignatureProvider SignatureAlgorithm을 만들 수 없습니다 : 'SHA256',
하기 권장 코드 :
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(symmetricKey), Microsoft.IdentityModel.Tokens.SecurityAlgorithms.HmacSha256Signature)
하지만 SecurityAlgorithms.RsaSha256Signature 작동하지 않습니다.
Microsoft.IdentityModel.Tokens.SigningCredentials SigningCredentials = new Microsoft.IdentityModel.Tokens.SigningCredentials(_signingKey, SecurityAlgorithms.RsaSha256Signature);
아래 오류가 있습니다.
DX10634 : SignatureProvider를 만들 수 없습니다.
은 SignatureAlgorithm 'SHA256', SecurityKey은 'Microsoft.IdentityModel.Tokens.SymmetricSecurityKey은'나는의 Sha256에 대한 JWT 토큰을 변환 할 필요가
를 지원하지 않습니다. 친절하게 샘플 코드로 솔루션을 제공하십시오.내 코드를 찾아주세요 :
string _privateSecretKey = "MIIEogIBAAKCAQEAytYejMhaYjZwFgqP7WKh2bkf08=";
Microsoft.IdentityModel.Tokens.SymmetricSecurityKey _signingKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(Encoding.ASCII.GetBytes(_privateSecretKey));
Microsoft.IdentityModel.Tokens.SigningCredentials SigningCredentials = new Microsoft.IdentityModel.Tokens.SigningCredentials(_signingKey, SecurityAlgorithms.RsaSha256Signature);
JwtHeader head = new JwtHeader();
head.Add("kid", "firstpublickey");//TBD
string sNewGuid = Guid.NewGuid().ToString("n");
var claims = new[]
{
new Claim(JwtRegisteredClaimNames.Iss, oTokenPostData.ClientID),
new Claim(JwtRegisteredClaimNames.Sub, oTokenPostData.ClientID),
new Claim(JwtRegisteredClaimNames.Aud, oTokenPostData.tokenUri),
new Claim(JwtRegisteredClaimNames.Jti, sNewGuid),
new Claim(JwtRegisteredClaimNames.Exp, ((int)DateTime.Now.AddMinutes(55).Subtract(UnixEpoch).TotalSeconds).ToString(System.Globalization.CultureInfo.InvariantCulture)),
new Claim(JwtRegisteredClaimNames.Iat, ((int)DateTime.Now.Subtract(UnixEpoch).TotalSeconds).ToString(System.Globalization.CultureInfo.InvariantCulture))
};
JwtPayload payload = new JwtPayload(claims);
JwtSecurityToken jwt = new JwtSecurityToken(head, payload);
var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt);
RSA는 비대칭 알고리즘이다. 원시 RSA 객체가있는 경우에는 RsaSecurityKey가 필요하고 인증서가있는 경우 X509SecurityKey가 필요합니다. (확실하지 않은 경우 그 유일한 문제, 따라서 대답 대신 대답) – bartonjs