I am working on an integration with a third-party application. The payload is signed with JWS using the nimbus.jose library. However, nimbus.jose is not used in .NET Core.
How can I convert this code to .NET Core? I’ve tried a few methods but haven’t found a solution. Can you help me convert this code to .NET Core?
Example Java code:
`// Load JWK Json From File, DB or Vault. Vault is recommended.
//JWK key file is explicitly built into the code to show its contents. You should
not use this approach.
final String jwkJson = "{"kty":"oct","use":"sig","kid":"b5de4c42-9064-
43a9-8235-aedcfc1f7ac3","k":"0UJ0NmGjGX2fmNyUeXsFChzTbC3b-GhqOIaoHE2d4U","alg":"HS256"}";
// Payload Json
final String payload = "{
"meta": {
"id": "acde070d-8c4c-4f0d-9d8a-162843c10333",
"timestamp": 1685645139
},
"data": {
"orderId": "467645734901236734",
"binNumbers": ["34055607"],
"price": {
"amount": "10000",
"currency": 949
}
}";
// Parse JWK
final JWK jwk = JWK.parse(jwkJson);
// Create JWS Object
final JWSObject jws = new JWSObject(
new JWSHeader.Builder(JWSAlgorithm.HS256).keyID(jwk.getKeyID()).build(),
new Payload(payload));
// Sign JWS
jws.sign(new MACSigner(jwk.toOctetSequenceKey()));
// Final JWS String
final String httpBody = jws.serialize();`
Bu soruya verebileceğiniz cevap aşağıdaki gibi olabilir:
I tried using various libraries and approaches in .NET Core, such as System.IdentityModel.Tokens.Jwt and Microsoft.IdentityModel.Tokens. My goal was to replicate the functionality of the nimbus.jose library to validate and decode the JWS signed payload. However, I encountered issues with decoding the token and verifying the signature.
Specifically, I attempted to:
Use JwtSecurityTokenHandler to read and validate the JWS token.
Create security keys and signing credentials similar to those used in nimbus.jose.
Implement custom validation methods to match the signature verification process.
Despite these efforts, I was unable to successfully verify and decode the payload as I expected. I was hoping for a straightforward method or a library in .NET Core that could handle JWS tokens in a way similar to nimbus.jose, ensuring compatibility with the existing third-party integration.
Feo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.