title: Why does 65537 not base64URL encode to "AQAB" using CryptoPP?
body: <p>I'm using CryptoPP to generate an RSA key pair to allow authentication for a game server. I need to base64URL encode my public exponent and modulus to include in a JWK but am having some problems.
  The code shows how I generate the RSA keys, extract the exponent and encode it:</p>
  
  <pre><code>typedef InvertibleRSAFunction RSAPrivateKey;
  typedef RSAFunction RSAPublicKey;
  
  RSAPrivateKey privateKey;
  privateKey.Initialize( rng, 1024);
  
  RSAPublicKey publicKey( privateKey );
  
  const Integer&amp; e = privateKey.GetPublicExponent();
  
  Base64Encoder exponentSink(new StringSink(exponentString));
  e.DEREncode(exponentSink);
  exponentSink.MessageEnd();
  base64URL(exponentString);
  
  cout &lt;&lt; "exponentString: " &lt;&lt; exponentString &lt;&lt; endl;
  </code></pre>
  
  <p>The base64URL function just filters the string for the =,+,\n and / characters to make it base64URL.</p>
  
  <p>I know that CryptoPP uses an exponent of 17, and the code above encodes this as "AgER".
  I've read from numerous sources that 65537 encodes as "AQAB" and I tried this as a test by manually setting e to this. When I do this the output is "AgMBAAE", not "AQAB".</p>
  
  <p>When I use an online converter such as <a href="https://www.base64encode.org/" rel="noreferrer">https://www.base64encode.org/</a> the output is instead "NjU1Mzc".</p>
  
  <p>Can someone explain where all these differences come from and what the correct encoding of 17 is? Thanks!</p>