I work at a healthcare software provider that is integrating with NHS and so I'm working on the example given in application-restricted-signed-jwt-tutorials/csharp.
I created an application and generated keys using openssl commands as described here:
https://digital.nhs.uk/developer/guides-and-documentation/security-and-authorisation/application-restricted-restful-apis-signed-jwt-authentication#step-2-generate-a-key-pair
export KID=test-2
openssl genrsa -out $KID.pem 4096
openssl rsa -in $KID.pem -pubout -outform PEM -out $KID.pem.pub
The keyfiles I generated end with .pem, and when I change over to .key and run the program, I get the following error while loading the private key:
AsnContentException: The provided data is tagged with 'Universal' class value '16', but it should have been 'Universal' class value '2'.
Which is thrown within the FromPrivateKey function in the JwtHandler class, on line 72 in this file: https://github.com/NHSDigital/hello-world-auth-examples/blob/main/application-restricted-signed-jwt-tutorials/csharp/auth/JwtHandler.cs
This is the line that fails to load the RSA key and instead throws the above error:
rsa.ImportRSAPrivateKey(keyBytes, out _);