core/src/main/java/org/springframework/security/converter/RsaKeyConverters.java
public static Converter<InputStream, RSAPublicKey> x509() {
		KeyFactory keyFactory = rsaFactory();
		return source -> {
			List<String> lines = readAllLines(source);
			Assert.isTrue(!lines.isEmpty() && lines.get(0).startsWith(X509_PEM_HEADER),
					"Key is not in PEM-encoded X.509 format, " +
							"please check that the header begins with -----" + X509_PEM_HEADER + "-----");
			String base64Encoded = lines.stream()
					.filter(RsaKeyConverters::isNotX509Wrapper)
					.collect(Collectors.joining());
			byte[] x509 = Base64.getDecoder().decode(base64Encoded);

			try {
				return (RSAPublicKey) keyFactory.generatePublic(
						new X509EncodedKeySpec(x509));
			} catch (Exception e) {
				throw new IllegalArgumentException(e);
			}
		};
	}
public static Converter<InputStream, RSAPublicKey> x509() {
		KeyFactory keyFactory = rsaFactory();
		return source -> {
			List<String> lines = readAllLines(source);
			Assert.isTrue(!lines.isEmpty() && lines.get(0).startsWith(X509_PEM_HEADER),
					"Key is not in PEM-encoded X.509 format, " +
							"please check that the header begins with -----" + X509_PEM_HEADER + "-----");
			String base64Encoded = lines.stream()
					.filter(RsaKeyConverters::isNotX509Wrapper)
					.collect(Collectors.joining());
			byte[] x509 = Base64.getDecoder().decode(base64Encoded);

			try {
				return (RSAPublicKey) keyFactory.generatePublic(
						new X509EncodedKeySpec(x509));
			} catch (Exception e) {
				throw new IllegalArgumentException(e);
			}
		};
	}
public static Converter < InputStream , RSAPublicKey > x509 ( ) { KeyFactory keyFactory = rsaFactory ( ) ; return source -> { List < String > lines = readAllLines ( source ) ; Assert . isTrue ( ! lines . isEmpty ( ) && lines . get ( 0 ) . startsWith ( X509_PEM_HEADER ) , "Key is not in PEM-encoded X.509 format, " + "please check that the header begins with -----" + X509_PEM_HEADER + "-----" ) ; String base64Encoded = lines . stream ( ) . filter ( RsaKeyConverters :: isNotX509Wrapper ) . collect ( Collectors . joining ( ) ) ; byte [ ] x509 = Base64 . getDecoder ( ) . decode ( base64Encoded ) ; try { return ( RSAPublicKey ) keyFactory . generatePublic ( new X509EncodedKeySpec ( x509 ) ) ; } catch ( Exception e ) { throw new IllegalArgumentException ( e ) ; } } ; }
Construct a {@link Converter} for converting a PEM-encoded X.509 RSA Public Key
into a {@link RSAPublicKey}.

This converter does not close the {@link InputStream} in order to avoid making non-portable
assumptions about the streams' origin and further use.

@return A {@link Converter} that can read a PEM-encoded X.509 RSA Public Key and return a
{@link RSAPublicKey}.
Construct a { @link Converter } for converting a PEM - encoded X . 509 RSA Public Key into a { @link RSAPublicKey } .