Class WfEncryptionKey

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

public final class WfEncryptionKey extends Object implements Destroyable
Whiteflag encryption key class

This class represents a Whiteflag encryption key. Instances of this class represent the raw key, either pre-shared or negotiated, from which the actual key material for encryption methods 1 and 2 is created.

Since:
1.1
Whiteflag version:
v1-draft.6
Whiteflag standard x-reference:
5.2.3 Key and Token Derivation, 5.2.4 Message Encryption
  • Field Details

    • method

      public final WfEncryptionMethod method
      The encryption method for which this key is valid
  • Constructor Details

    • WfEncryptionKey

      public WfEncryptionKey(String rawPreSharedKey)
      Constructs a new Whiteflag encryption key from a raw pre-shared key
      Parameters:
      rawPreSharedKey - a hexadecimal string with the raw pre-shared encryption key
    • WfEncryptionKey

      public WfEncryptionKey(byte[] rawPreSharedKey)
      Constructs a new Whiteflag encryption key from a raw pre-shared key
      Parameters:
      rawPreSharedKey - a byte array with the raw pre-shared encryption key
    • WfEncryptionKey

      public WfEncryptionKey(String rawPublicKey, WfECDHKeyPair ecdhKeyPair) throws WfCryptoException
      Constructs a new Whiteflag encryption key through ECDH key negotiation
      Parameters:
      rawPublicKey - a hexadecimal string with an originator's raw 264-bit compressed public ECDH key
      ecdhKeyPair - the own ECDH key pair object
      Throws:
      WfCryptoException - if the encryption key cannot be created
      IllegalStateException - if the key pair has been destroyed
    • WfEncryptionKey

      public WfEncryptionKey(byte[] rawPublicKey, WfECDHKeyPair ecdhKeyPair) throws WfCryptoException
      Constructs a new Whiteflag encryption key through ECDH key negotiation
      Parameters:
      rawPublicKey - a byte array with an originator's raw 264-bit compressed public ECDH key
      ecdhKeyPair - the own ECDH key pair object
      Throws:
      WfCryptoException - if the encryption key cannot be created
      IllegalStateException - if the key pair has been destroyed
    • WfEncryptionKey

      public WfEncryptionKey(ECPublicKey ecPublicKey, WfECDHKeyPair ecdhKeyPair) throws WfCryptoException
      Constructs a new Whiteflag encryption key through ECDH key negotiation
      Parameters:
      ecPublicKey - a ECDH public key
      ecdhKeyPair - the own ECDH key pair object
      Throws:
      WfCryptoException - if the encryption key cannot be created
      IllegalStateException - if the key pair has been destroyed
  • Method Details

    • destroy

      public final void destroy()
      Destroys this Whiteflag cipher by clearing the encryption key
      Specified by:
      destroy in interface Destroyable
    • 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
    • getEncryptionMethod

      public final WfEncryptionMethod getEncryptionMethod()
      Returns the encryption method
      Returns:
      a string with the encryption method indicator
    • getSecretKey

      public final SecretKey getSecretKey(String context)
      Derive the secret cryptographic key from this Whiteflag encryption key
      Parameters:
      context - a hexadecimal string with information to bind the derived key to the intended context
      Returns:
      a java SecretKey object with the secret cryptographic key
      Throws:
      IllegalArgumentException - if the encryption key has been destroyed
    • getSecretKey

      public final SecretKey getSecretKey(byte[] context)
      Derive the secret cryptographic key from this Whiteflag encryption key
      Parameters:
      context - a byte array with information to bind the derived key to the intended context
      Returns:
      a java SecretKey object with the secret cryptographic key
      Throws:
      IllegalArgumentException - if the encryption key has been destroyed