Class XECUtils

java.lang.Object
org.forgerock.json.jose.utils.XECUtils

public final class XECUtils extends Object
Utilities for handling XEC keys for X25519 and X448 ECDH key agreement. These classes are only available from Java 11, so we use reflection to perform default behaviour on earlier JDKs (typically returning null).
  • Method Details

    • isXecKey

      public static boolean isXecKey(Key key)
      Determines whether the given key is a XECKey.
      Parameters:
      key - the key.
      Returns:
      true if XDH is available and this is a XECKey, or else false.
    • xecPrivateKey

      public static PrivateKey xecPrivateKey(SupportedEllipticCurve curve, byte[] privateValue)
      Converts a private scalar byte value into a XECPrivateKey on the given curve.
      Parameters:
      curve - the curve. Must be either X25519 or X448.
      privateValue - the private scalar value.
      Returns:
      the XECPrivateKey corresponding to the given curve and private value.
      Throws:
      UnsupportedOperationException - if XDH support is not available.
      IllegalArgumentException - if the curve is not X25519 or X448 or if there is a problem with the scalar.
    • xecPublicKey

      public static PublicKey xecPublicKey(SupportedEllipticCurve curve, BigInteger uCoord)
      Converts a public u-coordinate into a XECPublicKey on the given curve.
      Parameters:
      curve - the curve. Must be either X25519 or X448.
      uCoord - the public u coordinate value.
      Returns:
      the XECPublicKey corresponding to the given curve and coordinate.
      Throws:
      UnsupportedOperationException - if XDH support is not available.
      IllegalArgumentException - if the curve is not X25519 or X448 or there is a problem with the u-coordinate.
    • publicUCoordinate

      public static byte[] publicUCoordinate(PublicKey publicKey)
      Returns the little-endian bytes of the public u-coordinate of the given XECPublicKey.
      Parameters:
      publicKey - the public key.
      Returns:
      the unsigned big-endian bytes of the public u-coordinate.
      Throws:
      IllegalStateException - if XDH support is not available.
      IllegalArgumentException - if the key is not a XECPublicKey.
    • privateScalarValue

      public static byte[] privateScalarValue(PrivateKey privateKey)
      Returns the private scalar value for the given XECPrivateKey.
      Parameters:
      privateKey - the private key.
      Returns:
      the private scalar value.
      Throws:
      IllegalStateException - if XDH support is not available.
      IllegalArgumentException - if the key is not a XECPrivateKey.
    • curve

      public static SupportedEllipticCurve curve(Key key)
      Returns the curve that this XECKey is for.
      Parameters:
      key - the key. Must be a XECKey.
      Returns:
      the supported elliptic curve for this key.
      Throws:
      IllegalStateException - if XDH support is not available.
      IllegalArgumentException - if the key is not a XECKey.
    • namedCurveParams

      public static AlgorithmParameterSpec namedCurveParams(Key key)
      Returns the NamedCurveParameters for this key.
      Parameters:
      key - the key. Must be a XECKey.
      Returns:
      the NamedCurveParameters for this key.
      Throws:
      IllegalArgumentException - if the key is not a XECKey.
      IllegalStateException - if XDH support is not available.