There is an application that creates a base64 encoded public key with the following commands:
openssl ecparam -genkey -name prime256v1 -out ecdsa.pem
openssl ec -noout -text -conv_form compressed -in ecdsa.pem | grep '^pub:' -A 3 | tail -n 3 | tr -d ' \n:' | xxd -r -p | base64
How do I use this public key in Java? According to my research it should work with this code, but I get an exception that the key is too long:
EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(Base64.getDecoder().decode("base64-from-above");
KeyFactory keyFactory = KeyFactory.getInstance("EC");
PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);