我的智威湯遜令牌看起來像如下:如何加密Web Api C#中的JWT令牌?
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9leGFtcGxlLm9yZyIsImF1ZCI6Imh0dHA6XC9cL2V4YW1wbGUuY29tIiwiaWF0IjoxMzU2OTk5NTI0LCJuYmYiOjEzNTcwMDAwMDAsImV4cCI6MTQwNzAxOTYyOSwianRpIjoiaWQxMjM0NTYiLCJ0eXAiOiJodHRwczpcL1wvZXhhbXBsZS5jb21cL3JlZ2lzdGVyIiwidGVzdC10eXBlIjoiZm9vIn0.UGLFIRACaHpGGIDEEv-4IIdLfCGXT62X1vYx7keNMyc
如果我複製上面的JWT令牌,並將其粘貼在https://jwt.io/那麼實際的信息顯示這樣
我想加密JWT令牌無法在Web Api中訪問我的信息。所以,我想使用任何加密算法,如果是這樣,請給我提供適當的解決方案
這是我的Startup.cs文件來授權JWT令牌。
// Api controllers with an [Authorize] attribute will be validated with JWT
app.UseJwtBearerAuthentication(
new JwtBearerAuthenticationOptions
{
AuthenticationMode = AuthenticationMode.Active,
AllowedAudiences = new[] { audience },
IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[]
{
new SymmetricKeyIssuerSecurityTokenProvider(issuer, secret)
}
});
}
雖然JWT允許對令牌進行加密,但通常沒有必要,因爲連接已經通過TLS/SSL進行了保護。 – Dirk