C
C#3mo ago
IbraDev💻

Exception Signing Algorithm

in my program im using HmacSha512Signature but as soon as i start to execute to generate JWT token my programm throws an exception that my key size must be greater than 512
No description
18 Replies
lycian
lycian3mo ago
How are you creating the JwtSecurityToken? It seems likely the signingCredentials are made with a key that is 136 bits insted of 512
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
IbraDev💻
IbraDev💻3mo ago
appsettingsjason
No description
IbraDev💻
IbraDev💻3mo ago
No description
lycian
lycian3mo ago
it seems likely the signingCredentials are made with a key that is 136 bits insted of 512
what is cred? min repro code would be preferable, can def help with that
IbraDev💻
IbraDev💻3mo ago
No description
IbraDev💻
IbraDev💻3mo ago
Im sorry... i dont now how to do that stuff im likely new to github
lycian
lycian3mo ago
Is this code on github?
IbraDev💻
IbraDev💻3mo ago
No description
IbraDev💻
IbraDev💻3mo ago
yes but private so i found out when i change my "My secret key" its always ends in an exception bc i use more bits or less bits
lycian
lycian3mo ago
no worries. I'm no expert, but I think it's in how you're creating the token . You might have more success with this
var tokenHandler = new JwtSecurityTokenHandler();
var tokenDescriptor = new SecurityTokenDescriptor
{
Issuer = "yourdomain.com",
Audience = "yourdomain.com",
Claims = user.Claims, // Add any custom claims here
Expires = DateTime.Now.AddDays(1),
SigningCredentials = cred
};
var token = tokenHandler.CreateToken(tokenDescriptor);
var jwt = tokenHandler.WriteToken(token);
var tokenHandler = new JwtSecurityTokenHandler();
var tokenDescriptor = new SecurityTokenDescriptor
{
Issuer = "yourdomain.com",
Audience = "yourdomain.com",
Claims = user.Claims, // Add any custom claims here
Expires = DateTime.Now.AddDays(1),
SigningCredentials = cred
};
var token = tokenHandler.CreateToken(tokenDescriptor);
var jwt = tokenHandler.WriteToken(token);
IbraDev💻
IbraDev💻3mo ago
so which part do have to replace it with
lycian
lycian3mo ago
your new JwtSecurityToken should be made with CreateToken
IbraDev💻
IbraDev💻3mo ago
No description
IbraDev💻
IbraDev💻3mo ago
the same exception
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX3mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View