Class WfECDHKeyPair
java.lang.Object
org.whiteflagprotocol.java.crypto.WfECDHKeyPair
- All Implemented Interfaces:
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
-
Constructor Summary
ConstructorDescriptionConstructs a new Whiteflag ECDH key pairWfECDHKeyPair
(ECPrivateKey ecPrivateKey) Constructs a new Whiteflag ECDH key pair from an existing private key -
Method Summary
Modifier and TypeMethodDescriptionstatic final byte[]
compressPublicKey
(ECPublicKey ecPublicKey) Compresses an ECDH public key to a raw 264-bit compressed public ECDH keystatic final KeyPair
Creates a new random ECDH key pair with the curve specified for Whiteflag key negotiationstatic final KeyPair
createKeyPair
(ECPrivateKey ecPrivateKey) Creates an ECDH key pair from an existing private key with the curve specified for Whiteflag key negotiationstatic final ECPrivateKey
createPrivateKey
(byte[] rawPrivateKey) Creates an ECDH private key object from a byte arraystatic final ECPublicKey
createPublicKey
(byte[] rawPublicKey) Creates an ECDH public key object from a byte arraystatic final ECPublicKey
createPublicKey
(String rawPublicKey) Creates an ECDH public key object from a byte arrayfinal void
destroy()
Destroys this Whiteflag ECDH key pair by clearing the private keyfinal ECPublicKey
Returns the public key of this key pairfinal byte[]
Returns the raw public key of the ECDH key pairfinal boolean
Determine if this Whiteflag cipher has been destroyed.final byte[]
negotiateKey
(byte[] rawPublicKey) Calculates the negotiated shared key with an originatorfinal byte[]
negotiateKey
(ECPublicKey ecPublicKey) Calculates the negotiated shared key with an originator
-
Field Details
-
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
Constructs a new Whiteflag ECDH key pair- Throws:
WfCryptoException
- if the key pair could not be created
-
WfECDHKeyPair
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
Destroys this Whiteflag ECDH key pair by clearing the private key- Specified by:
destroy
in interfaceDestroyable
- Throws:
DestroyFailedException
- if the destroy operation failsIllegalStateException
- 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 interfaceDestroyable
- Returns:
- TRUE if destroyed, else FALSE
-
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
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 invalidIllegalStateException
- if the key pair has been destroyed
-
negotiateKey
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 invalidIllegalStateException
- if the key pair has been destroyed
-
createKeyPair
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
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
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
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
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
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
-