Comments (1)
Got it working, big thanks to @abatishchev .
Here's the snippet if you need to get this working with RSA. Obviously this key pair is not real, and you should never save a keypair directly into your code. This is helpful for the example though since there's so many possible formats of RSA keys.
public static string IssueJwtWithKeysOnly(Dictionary<string,object> claims)
{
// var pub = @"-----BEGIN PUBLIC KEY-----
// MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDTGvumTtnGD5S+xw6oH3LOuysp
// j6s4KDo6fsbGGAzp8Jb2PBRd/Ree0+FtzNQoVaDka2uCocnuX8+YTpv6J7zDN0zB
// YWuqBmQVW+5FTjPGkdKwgchzTGLdPtzdUllgqkaDdogBCcyBq6cnDT2U5q1p1j5e
// +Pnzt4gXGnBoETBzpwIDAQAB
// -----END PUBLIC KEY-----";
// var priv = @"-----BEGIN RSA PRIVATE KEY-----
// MIICXwIBAAKBgQDTGvumTtnGD5S+xw6oH3LOuyspj6s4KDo6fsbGGAzp8Jb2PBRd
// /Ree0+FtzNQoVaDka2uCocnuX8+YTpv6J7zDN0zBYWuqBmQVW+5FTjPGkdKwgchz
// TGLdPtzdUllgqkaDdogBCcyBq6cnDT2U5q1p1j5e+Pnzt4gXGnBoETBzpwIDAQAB
// AoGBAIIGhqWCv6O8iROQq7hl1mL66bTppr4qGONanrf4rEuTQohbrPfPIbNUMe9d
// T/ef9j964ndNi4DlRoo7MNs9iodcqX8KMnNXOlV9iBi+7mpe8jmHC5ZGAoTGnPt5
// vNXPAGtWbSuan8dDkFbbAikmtzIUJdlhj60sU9Q7vpYacI6xAkEA7BcCDQ8JyQNg
// gSKgyyN5T/Rzdj68B1JOVvZtVoQLtyf84XK4E4uUTJ2U+3FNr0FtCV3qK7B6IQbv
// QfOMzbsBRQJBAOTolIXvE+Gci3SDyU0zRp1uAggEdnUX/6vul7fLcPT0+9COD7H6
// 2WKxYGDDAVXI9KyO/YNe+DYwYXi0wW64MfsCQQCN9ofVMmW/6bft7tShUgNwgJ2t
// TKvj+yoAQM4eZ+hjijgVmNX3ascSCu+7Araj28OlDkPxYX0Ovwy/q6PPUdPBAkEA
// 4jK2OZdjhQkFgVCNBj2KJR1E4plOWS0q18JAqD1f1J+ViqQm/FAOqoju3Q817YhT
// x4TRHRUmn521Y+ryTi+0KwJBAK4D7P7sKAiUYS/Q9TXv1KqW76Vv8JaPDSkhu8bW
// JYmM7mkwoUEEkV7v4Zkp74rmiG+9wmOxBsAjEcHl/IC7Pac=
// -----END RSA PRIVATE KEY-----";
var pubRSA = RSA.Create();
pubRSA.ImportFromPem(pub);
var privRSA = RSA.Create();
privRSA.ImportFromPem(priv);
string token = JwtBuilder.Create()
.WithAlgorithm(new RS256Algorithm(pubRSA,privRSA)).AddClaims(claims).Encode();
return token;
}
from jwt.
Related Issues (20)
- "Illegal base64url string" when try to decode token HOT 20
- Not properly serilized object in fluent version of Decode HOT 9
- Support Asynchronous Signing in IJwtAlgorithm interface HOT 5
- Why has the HMAC SHA algorithm become obsolete? HOT 2
- InvalidOperationException occurs in Decode() after DecodeHeader(). HOT 2
- Support JWT authentication with public key using ES256 algorithm on .NET Compact Framework 3.5 HOT 2
- Decode does not break on wrong signature HOT 5
- How to enable MODERN_DOTNET? HOT 5
- Dotnet 8.0 AOT Issues
- Where is `RS256Algorirhm`? HOT 1
- Expiry Time is added to claims when decoding HOT 3
- Having trouble with first example Encode() HOT 2
- Expired token not throwing TokenExpiredException HOT 7
- Null reference error when trying to Decode HOT 2
- How to use IJwtValidator.Validate / TryValidate? HOT 5
- jwt is missing NuGet package README file HOT 2
- X21 HOT 1
- X21 HOT 1
- System.Text.Json should only be a dependency for .NET standard HOT 3
- Authorization throwing an exception: IDX10503 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jwt.