title: Discrepancy between Java's public key representation and RFC 8410
body: <p><a href="https://www.rfc-editor.org/rfc/rfc8410" rel="nofollow noreferrer">RFC 8410</a> lists this as an example of a Ed25519 public key: <code>MCowBQYDK2VwAyEAGb9ECWmEzf6FQbrBZ9w7lshQhqowtrbLDFw4rXAxZuE=</code></p>
  <p>Decoding this with an ASN.1 decoder, this becomes:</p>
  <pre><code>30 2A
    30 05
      06 03 2B6570 // Algorithm Identifier
    03 21 0019BF44096984CDFE8541BAC167DC3B96C85086AA30B6B6CB0C5C38AD703166E1
  </code></pre>
  <p>As expected, this matches the <code>SubjectPublicKeyInfo</code> definition in the RFC.</p>
  <p>Using the Sun cryptography provider in Java 11+ I can use this code to generate an X25519 (not Ed25519 - which is the difference in the algorithm identifier below) public key:</p>
  <pre class="lang-java prettyprint-override"><code>import java.security.KeyPairGenerator;
  import java.util.Base64;
  
  public class PrintPublicKey {
      public static void main(String args[]) throws Exception {
          KeyPairGenerator generator = KeyPairGenerator.getInstance(&quot;X25519&quot;);
          byte[] encodedPublicKey = generator.generateKeyPair().getPublic().getEncoded();
          System.out.println(Base64.getEncoder().encodeToString(encodedPublicKey));
      }
  }
  </code></pre>
  <p>Which will output something like: <code>MCwwBwYDK2VuBQADIQDlXKI/cMoICnQRrV+4c//viHnXMoB190/z2MX/otJQQw==</code></p>
  <p>Decoding this with an ASN.1 decoder, this becomes:</p>
  <pre><code>30 2C
    30 07
      06 03 2B656E // Algorithm Identifier
      05 00        // Algorithm Parameters - NULL
    03 21 00E55CA23F70CA080A7411AD5FB873FFEF8879D7328075F74FF3D8C5FFA2D25043
  </code></pre>
  <p>This has an explicit <code>NULL</code> after the object identifier. Is this valid according to the specification? It says:</p>
  <blockquote>
  <p>In this document, we define four new OIDs for identifying the different curve/algorithm pairs: the curves being curve25519 and curve448 and the algorithms being ECDH and EdDSA in pure mode.</p>
  <p><strong>For all of the OIDs, the parameters MUST be absent.</strong></p>
  </blockquote>