public static JsonWebKey fromEC ( KeyPair keyPair , Provider provider ) { ECPublicKey apub = ( ECPublicKey ) keyPair . getPublic ( ) ; ECPoint point = apub . getW ( ) ; ECPrivateKey apriv = ( ECPrivateKey ) keyPair . getPrivate ( ) ; if ( apriv != null ) { return new JsonWebKey ( ) . withKty ( JsonWebKeyType . EC ) . withCrv ( getCurveFromKeyPair ( keyPair , provider ) ) . withX ( point . getAffineX ( ) . toByteArray ( ) ) . withY ( point . getAffineY ( ) . toByteArray ( ) ) . withD ( apriv . getS ( ) . toByteArray ( ) ) . withKty ( JsonWebKeyType . EC ) ; } else { return new JsonWebKey ( ) . withKty ( JsonWebKeyType . EC ) . withCrv ( getCurveFromKeyPair ( keyPair , provider ) ) . withX ( point . getAffineX ( ) . toByteArray ( ) ) . withY ( point . getAffineY ( ) . toByteArray ( ) ) . withKty ( JsonWebKeyType . EC ) ; } }
Converts EC key pair to JSON web key .