Class 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 Detail

      • 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.