Class WfECDHKeyPair

java.lang.Object
org.whiteflagprotocol.java.crypto.WfECDHKeyPair
All Implemented Interfaces:
Destroyable

public final class WfECDHKeyPair extends Object implements Destroyable
Whiteflag ECDH Key Pair class

This class represents an Elleptic Curve Diffie-Hellmann key pair used by Whiteflag for cryptographic key negotiation. The elliptic curve parameters that must be used for Whiteflag are defined by the brainpoolP256r1 curve as specified in RFC 5639. Public keys are shared as raw 264-bit compressed public ECDH keys.

Since:
1.1
Whiteflag version:
v1-draft.6
Whiteflag standard x-reference:
5.2.2 Key Agreement
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The name of the elleptic curve used by Whiteflag for ECDH hey negotiation
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new Whiteflag ECDH key pair
    Constructs a new Whiteflag ECDH key pair from an existing private key
  • Method Summary

    Modifier and Type
    Method
    Description
    static final byte[]
    Compresses an ECDH public key to a raw 264-bit compressed public ECDH key
    static final KeyPair
    Creates a new random ECDH key pair with the curve specified for Whiteflag key negotiation
    static final KeyPair
    Creates an ECDH key pair from an existing private key with the curve specified for Whiteflag key negotiation
    static final ECPrivateKey
    createPrivateKey(byte[] rawPrivateKey)
    Creates an ECDH private key object from a byte array
    static final ECPublicKey
    createPublicKey(byte[] rawPublicKey)
    Creates an ECDH public key object from a byte array
    static final ECPublicKey
    createPublicKey(String rawPublicKey)
    Creates an ECDH public key object from a byte array
    final void
    Destroys this Whiteflag ECDH key pair by clearing the private key
    Returns the public key of this key pair
    final byte[]
    Returns the raw public key of the ECDH key pair
    final boolean
    Determine if this Whiteflag cipher has been destroyed.
    final byte[]
    negotiateKey(byte[] rawPublicKey)
    Calculates the negotiated shared key with an originator
    final byte[]
    Calculates the negotiated shared key with an originator

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CURVENAME

      public static final String CURVENAME
      The name of the elleptic curve used by Whiteflag for ECDH hey negotiation
      See Also:
      Whiteflag standard x-reference:
      5.2.2 Key Agreement
  • Constructor Details

    • WfECDHKeyPair

      public WfECDHKeyPair() throws WfCryptoException
      Constructs a new Whiteflag ECDH key pair
      Throws:
      WfCryptoException - if the key pair could not be created
    • WfECDHKeyPair

      public WfECDHKeyPair(ECPrivateKey ecPrivateKey) throws WfCryptoException
      Constructs a new Whiteflag ECDH key pair from an existing private key
      Parameters:
      ecPrivateKey - the private key object
      Throws:
      WfCryptoException - if the private key is invalid or the key pair could not be created
  • Method Details

    • destroy

      public final void destroy() throws DestroyFailedException
      Destroys this Whiteflag ECDH key pair by clearing the private key
      Specified by:
      destroy in interface Destroyable
      Throws:
      DestroyFailedException - if the destroy operation fails
      IllegalStateException - if the encryption key has already been destroyed
    • isDestroyed

      public final boolean isDestroyed()
      Determine if this Whiteflag cipher has been destroyed.
      Specified by:
      isDestroyed in interface Destroyable
      Returns:
      TRUE if destroyed, else FALSE
    • getPublicKey

      public final ECPublicKey getPublicKey()
      Returns the public key of this key pair
      Returns:
      a public key object
      Throws:
      IllegalStateException - if the key pair has been destroyed
    • getRawPublicKey

      public final byte[] getRawPublicKey()
      Returns the raw public key of the ECDH key pair
      Returns:
      a byte array with the raw 264-bit compressed public ECDH key
      Throws:
      IllegalStateException - if the key pair has been destroyed
    • negotiateKey

      public final byte[] negotiateKey(byte[] rawPublicKey) throws WfCryptoException
      Calculates the negotiated shared key with an originator
      Parameters:
      rawPublicKey - the originator's raw 264-bit compressed public ECDH key
      Returns:
      a byte array with the negotiated secret key
      Throws:
      WfCryptoException - if the raw key or any of the parameters is invalid
      IllegalStateException - if the key pair has been destroyed
    • negotiateKey

      public final byte[] negotiateKey(ECPublicKey ecPublicKey) throws WfCryptoException
      Calculates the negotiated shared key with an originator
      Parameters:
      ecPublicKey - the originator's ECDH public key
      Returns:
      a byte array with the negotiated secret key
      Throws:
      WfCryptoException - if the raw key or any of the parameters is invalid
      IllegalStateException - if the key pair has been destroyed
    • createKeyPair

      public static final KeyPair createKeyPair() throws WfCryptoException
      Creates a new random ECDH key pair with the curve specified for Whiteflag key negotiation
      Returns:
      a key pair object
      Throws:
      WfCryptoException - if the new ECDH key pair could not be created
    • createKeyPair

      public static final KeyPair createKeyPair(ECPrivateKey ecPrivateKey) throws WfCryptoException
      Creates an ECDH key pair from an existing private key with the curve specified for Whiteflag key negotiation
      Parameters:
      ecPrivateKey - the ECDH private key object
      Returns:
      a key pair object
      Throws:
      WfCryptoException - if an ECDH key pair could not be generated from the provided private key
    • createPublicKey

      public static final ECPublicKey createPublicKey(String rawPublicKey) throws WfCryptoException
      Creates an ECDH public key object from a byte array
      Parameters:
      rawPublicKey - a string with the raw 264-bit compressed public ECDH key
      Returns:
      an ECDH public key object
      Throws:
      WfCryptoException - if the raw key or any of the curve parameters is invalid
    • createPublicKey

      public static final ECPublicKey createPublicKey(byte[] rawPublicKey) throws WfCryptoException
      Creates an ECDH public key object from a byte array
      Parameters:
      rawPublicKey - a byte array with the raw 264-bit compressed public ECDH key
      Returns:
      an ECDH public key object
      Throws:
      WfCryptoException - if the raw key or any of the curve parameters is invalid
    • createPrivateKey

      public static final ECPrivateKey createPrivateKey(byte[] rawPrivateKey) throws WfCryptoException
      Creates an ECDH private key object from a byte array
      Parameters:
      rawPrivateKey - a byte array with the raw private ECDH key
      Returns:
      an ECDH private key object
      Throws:
      WfCryptoException - if the raw key or any of the curve parameters is invalid
    • compressPublicKey

      public static final byte[] compressPublicKey(ECPublicKey ecPublicKey)
      Compresses an ECDH public key to a raw 264-bit compressed public ECDH key
      Parameters:
      ecPublicKey - an ECDH public key object
      Returns:
      a byte array with the raw 264-bit compressed public ECDH key