Thanks for the response. The key is generated and signed by our license server and they providethe public key information at https://dev.id.envirosim.com/.well-known/jwks.json. [Although this is in our domain the actual signing and license delivery is done by a third party 10Duke.] I can verify the jwt and signature on https://www.jwt.io/
From this I thought the signature was RSA and alg=RS256
I had already taken a look at this project … unfortunately it uses the TRSA class which uses a PEM format for the Public Key and does not allow you to specify the key from a jwks that specifies “n” and “e” - see JWK JSON below. A second problem is that (I think) the TRSA class requires “OpenSSL” which I cannot install on every client computer.
The kid is the key id and the jwt header also includes a kid so that you know which key to use from the JWKS (i.e. the one with the matching kid).
When I run the project that you attached I get an error saying it could not initialise OpenSSL. Also if you look at the code for TRSA.Verify (below) you can see that the first thing that it does is call LoadOpenSSL…. and when that procedure is called I get the error message '[OpenSSL] Unable to load OpenSSL libraries’ so I am pretty sure that it does use OpenSSL. That is why I am trying to use the class TRSAEncSign which I hope does not use OpenSSL
class function TRSA.Verify(const AInput, ASignature, AKey: TBytes; AAlg: TRSAAlgorithm): Boolean;
var
LRsa: PRSA;
begin
LoadOpenSSL;
LRsa := LoadPublicKey(AKey);
try
Result := InternalVerify(AInput, ASignature, LRsa, AAlg);
finally
RSA_Free(LRsa);
end;
end;
function TRSAEncSign.Verify(m, s: string): Integer;
var
temp: string;
Modulus, signature, mPB, PublicExponent: TBytes;
conv: TConvert;
Core: TRSACore;
begin
if FModulus = '' then
raise ECryptoPack.Create('Verify: The modulus is empty!');
if FPublicExponent = '' then
raise ECryptoPack.Create('Verify: The public exponent is empty!');
...
TRSA was in the original project, but is no longer in the one I modified.
I was not able to get the TRSAEncSign object to directly use the modulus and exponent but based on your example I decided to convert the modulus and exponent from the JWKS into a PEM file and then use a method similar to the one you used in the JOSE1 example. I have attached a working copy of this in case other people want to verify a JWT from a public jwks.json.