Describe the bug

When a ResourceKeyConverterAdapter is registered with the conversion service, it's registered as a String -> java.security.Key converter as the adapter's type constraint is T extends Key. This means that the conversion service is incapable of a String to RSAPublicKey or RSAPrivateKey conversion.

To Reproduce

The following test will reproduce the problem:

@Test
void whenX509ConverterIsRegisteredWithConversionServiceThenConversionToRSAPublicKeyIsPossible() {
    GenericConversionService conversionService = new GenericConversionService();
    conversionService.addConverter(new ResourceKeyConverterAdapter<>(RsaKeyConverters.x509()));
    assertThat(conversionService.canConvert(String.class, RSAPublicKey.class)).isTrue();
}

Expected behavior The above test should pass. A workaround is to sub-class ResourceKeyConverterAdapter to provide additional type information:

@Test
void whenX509ConverterIsRegisteredWithConversionServiceUsingSubclassedAdapterThenConversionToRSAPublicKeyIsPossible() {
    GenericConversionService conversionService = new GenericConversionService();
    conversionService.addConverter(new ResourceKeyConverterAdapter<RSAPublicKey>(RsaKeyConverters.x509()) {
    });
    assertThat(conversionService.canConvert(String.class, RSAPublicKey.class)).isTrue();
}

Sample

See above.