@Test
    public void convertPublicKeyToFromRawKeySpec_works() throws Exception {
        byte[] rawPublicKey =
                decodeHex("d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a");
        KeyFactory keyFactory = KeyFactory.getInstance("Ed25519", conscryptProvider);
        PublicKey publicKey = keyFactory.generatePublic(new RawKeySpec(rawPublicKey));
        assertEquals("EdDSA", publicKey.getAlgorithm());

        // RawKeySpec returns the raw public key.
        RawKeySpec rawPublicKeySpec = keyFactory.getKeySpec(publicKey, RawKeySpec.class);
        assertEquals("raw", rawPublicKeySpec.getFormat());
        assertArrayEquals(rawPublicKey, rawPublicKeySpec.getEncoded());

        // getEncoded() returns an X.509 encoded public key.
        byte[] expectedX509Prefix = decodeHex("302a300506032b6570032100");
        byte[] encodedPublicKey = publicKey.getEncoded();
        assertEquals(44, encodedPublicKey.length);
        assertArrayEquals(expectedX509Prefix,
                Arrays.copyOfRange(encodedPublicKey, 0, expectedX509Prefix.length));
        assertArrayEquals(rawPublicKey,
                Arrays.copyOfRange(
                        encodedPublicKey, expectedX509Prefix.length, encodedPublicKey.length));

        // X509EncodedKeySpec returns the same encoding as getEncoded().
        X509EncodedKeySpec publicKeySpec =
                keyFactory.getKeySpec(publicKey, X509EncodedKeySpec.class);
        assertEquals("X.509", publicKeySpec.getFormat());
        assertArrayEquals(encodedPublicKey, publicKeySpec.getEncoded());

        assertThrows(InvalidKeySpecException.class,
                () -> keyFactory.getKeySpec(publicKey, PKCS8EncodedKeySpec.class));
    }
Implements a KeySpec that contains the raw bytes of a key.
common/src/test/java/org/conscrypt/EdDsaTest.java