Reputation: 992
I'm at a loss as to what is wrong here. I'm trying to create a JWT with RS SHA256. At handler.WriteToken I get this error:
IDX10634: Unable to create the SignatureProvider. Algorithm: 'System.String', SecurityKey: 'Microsoft.IdentityModel.Tokens.SymmetricSecurityKey' is not supported. The list of supported algorithms is available here: https://aka.ms/IdentityModel/supported-algorithms
The way I interpret it, it is telling me that I am specifying an unsupported algorithm, yet SecurityAlgorithms.RsaSha256 resolves to "RS256".
Any guidance would be appreciated. Below is my code.
Imports System.Security.Cryptography
Imports Microsoft.IdentityModel.Tokens
Imports System.IdentityModel.Tokens.Jwt
Public Function GetJWT()
Dim rsaPrivateKey As String = "MIIEvQI...small piece of key included here...J83wMcqFO4WXjrMXU="
Dim rsaPrivateKeyBytes() As Byte = System.Text.Encoding.Default.GetBytes(Base64UrlEncode(rsaPrivateKey))
Dim securityKey As Microsoft.IdentityModel.Tokens.SymmetricSecurityKey = New Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(rsaPrivateKeyBytes)
Dim credentials As SigningCredentials = New Microsoft.IdentityModel.Tokens.SigningCredentials(securityKey, SecurityAlgorithms.RsaSha256)
Dim header As JwtHeader = New JwtHeader(credentials)
Dim payload As JwtPayload = New JwtPayload()
payload.Item("test") = "this is a test"
Dim secToken As JwtSecurityToken = New JwtSecurityToken(header, payload)
Dim handler As JwtSecurityTokenHandler = New JwtSecurityTokenHandler()
Dim tokenString As String = handler.WriteToken(secToken)
Return tokenString
End Function
Public Function Base64UrlEncode(input As String) As String
Dim inputBytes() As Byte = System.Text.Encoding.UTF8.GetBytes(input)
Return Convert.ToBase64String(inputBytes).Replace("+", "-").Replace("/", "_").Replace("=", "")
End Function
Upvotes: 0
Views: 3689
Reputation: 599
According to the link you posted, RsaSha256
is not a supported symmetric algorithm. You need to try a symmetric algorithm, like SecurityAlgorithms.HmacSha256
.
Upvotes: 1