Shouldn't the boolean parameter for ExportParameters be true if withPrivateKey is true? I was trying a JWE validation with asymmetric key and it kept on failing with "Encryption Key Not found" error -which I think maybe due to this. In file src\JsonWebToken\Jwk.cs
if (withPrivateKey)
{
using var rsa = certificate.GetRSAPrivateKey();
if (!(rsa is null))
{
var rsaParameters = rsa.ExportParameters(false);
key = new RsaJwk(rsaParameters);
}
}
Also, it might be better to add a assert in test\JsonWebToken.Tests\JsonWebKeyTests.cs to check for jwk.HasPrivateKey property if the input certificate has a private key.
[Theory]
[MemberData(nameof(GetCertificates))]
public void CreateFromCertificate(X509Certificate2 certificate, bool hasPrivateKey, int keySize)
{
var jwk = Jwk.FromX509Certificate(certificate, hasPrivateKey);
Assert.Equal(keySize, jwk.KeySizeInBits);
if(hasPrivateKey)
{
Assert.True(jwk.HasPrivateKey);
}
}
Shouldn't the boolean parameter for ExportParameters be true if withPrivateKey is true? I was trying a JWE validation with asymmetric key and it kept on failing with "Encryption Key Not found" error -which I think maybe due to this. In file
src\JsonWebToken\Jwk.cs
Also, it might be better to add a assert in
test\JsonWebToken.Tests\JsonWebKeyTests.cs
to check for jwk.HasPrivateKey property if the input certificate has a private key.