C
C#9mo 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
lycian9mo 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 User9mo ago
Message Not Public
Sign In & Join Server To View
IbraDev💻
IbraDev💻OP9mo ago
appsettingsjason
No description
IbraDev💻
IbraDev💻OP9mo ago
No description
lycian
lycian9mo 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💻OP9mo ago
No description
IbraDev💻
IbraDev💻OP9mo ago
Im sorry... i dont now how to do that stuff im likely new to github
lycian
lycian9mo ago
Is this code on github?
IbraDev💻
IbraDev💻OP9mo ago
No description
IbraDev💻
IbraDev💻OP9mo 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
lycian9mo 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💻OP9mo ago
so which part do have to replace it with
lycian
lycian9mo ago
your new JwtSecurityToken should be made with CreateToken
IbraDev💻
IbraDev💻OP9mo ago
No description
IbraDev💻
IbraDev💻OP9mo ago
the same exception
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX9mo 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 User9mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server