private PublicKey decodePublicKey(final String pem, final String alg) {
        PublicKey publicKey = null;

        try {
            // decode to its constituent bytes
            String publicKeyPEM = pem;
            publicKeyPEM = publicKeyPEM.replace("-----BEGIN PUBLIC KEY-----\n", "");
            publicKeyPEM = publicKeyPEM.replace("-----END PUBLIC KEY-----", "");

            byte[] publicKeyBytes = SimplePEMEncoder.decode(publicKeyPEM);

            // create a key object from the bytes
            final X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicKeyBytes);
            KeyFactory keyFactory = KeyFactory.getInstance(alg);
            publicKey = keyFactory.generatePublic(keySpec);

        } catch (final RuntimeException | NoSuchAlgorithmException | InvalidKeySpecException e) {
            LOGGER.error("decodePublicKey() - alg: {}, message: {}", alg, LogUtil.exceptionMessage(e), e);
        }

        return publicKey;
    }
Verify the JSON Web Signature and then extract the user identity from it
stroom-security/stroom-security-common-impl/src/main/java/stroom/security/common/impl/StandardJwtContextFactory.java