title: How To validate Jwt Token for Apple Login (Backend validation). How to generate RSA Public key from modulus and exponent (n,e) in Java
body: <p>I'm looking for a way to validate apple's login token. <br>
  The validation must be done on backend side so i'm sure that i can add a new account safely.<br><br>
  Onother issue is that i need to convert the key <a href="https://appleid.apple.com/auth/keys" rel="nofollow noreferrer">https://appleid.apple.com/auth/keys</a> in xml format to Public Key pem format. <br>
  I have found a possible solution that I will post below.
  The code is implemented in Java</p>
  
  <pre><code>public static void main(String...args) throws Exception {
          String jwtAppleToken = ""; //copy here the token from apple
  
          //copied from https://appleid.apple.com/auth/keys
          final String base64UrlEncodedModulus = "lxrwmuYSAsTfn-lUu4goZSXBD9ackM9OJuwUVQHmbZo6GW4Fu_auUdN5zI7Y1dEDfgt7m7QXWbHuMD01HLnD4eRtY-RNwCWdjNfEaY_esUPY3OVMrNDI15Ns13xspWS3q-13kdGv9jHI28P87RvMpjz_JCpQ5IM44oSyRnYtVJO-320SB8E2Bw92pmrenbp67KRUzTEVfGU4-obP5RZ09OxvCr1io4KJvEOjDJuuoClF66AT72WymtoMdwzUmhINjR0XSqK6H0MdWsjw7ysyd_JhmqX5CAaT9Pgi0J8lU_pcl215oANqjy7Ob-VMhug9eGyxAWVfu_1u6QJKePlE-w"; 
          final String base64UrlEncodedExp = "AQAB";
  
          String publicKey = getPemPublicKeyFromBase64UrlEncodedXMLRSAKey(base64UrlEncodedModulus, base64UrlEncodedExp);
  
          System.out.println(verify(jwtAppleToken, publicKey));
  
          System.out.println("-----BEGIN PUBLIC KEY-----");
          System.out.println(publicKey);
          System.out.println("-----END PUBLIC KEY-----");
  
      }
  </code></pre>