Closed JT117 closed 1 year ago
My bad, I fooled myself with the asbytes() method that return the char code and not the decimal value >< Using the crate num-bigint solves my issue.
let exponent = BigInt::parse_bytes( exponent.as_bytes(), 10).unwrap().to_bytes_be();
let modulus = BigInt::parse_bytes( modulus.as_bytes(), 10).unwrap().to_bytes_be();
I want to validate the RS256 signature of a JWT Token with the public key modulus and exponent. The signature verification always fails with InvalidSignature with the modulus and exponent, but is valid if I load the public key file.
Sample code to reproduce:
The public key content:
The execution result :
In debug mode I can see the content of the DecodingKey structure is the same, but the kind differs. From file it is a DecodingKeyKind::SecretOrDer but from raw part it is DecodingKeyKind::RsaModulusExponent.
For what I can follow it all goes down to https://github.com/Keats/jsonwebtoken/blob/af684c146f288d993c632e15fb390f29ebe46683/src/crypto/mod.rs#L99-L103
The verify_ring seems to be fine but the rsa::verify_from_components return the InvalidSignature.
I will try to compare the code with the RFC to find out the bug but I don't know enough about RSA and signature verification. Any help finding/understanding the problem is appreciated 😄