EcdhKeyDerivation class ECDH
Performs ECDH key agreement and key derivation.
Use deriveKey to produce raw derived bytes via HKDF, or deriveAesKey to get a FortisAesKey directly.
For raw shared secret bytes (without HKDF), use deriveSharedSecret.
final pair = await Fortis.ecdh().generateKeyPair();
final theirPublicKey = (await Fortis.ecdh().generateKeyPair()).publicKey;
final derivation = Fortis.ecdh()
.curve(EcdhCurve.p256)
.keyDerivation(pair.privateKey);
// Derive raw key bytes
final keyBytes = derivation.deriveKey(theirPublicKey);
// Derive an AES key directly
final aesKey = derivation.deriveAesKey(theirPublicKey);
// Or get the raw shared secret
final secret = derivation.deriveSharedSecret(theirPublicKey);
See also:
- EcdhBuilder.keyDerivation, which builds this type with a validated key size.
- FortisEcdhPublicKey, the peer key every derivation takes.
- FortisAesKey, the symmetric key deriveAesKey returns.
- EcdhCurve, which both keys must agree on.
Constructors
- EcdhKeyDerivation({required FortisEcdhPrivateKey privateKey, int keySize = 256})
-
Creates an EcdhKeyDerivation with the given
privateKeyand optionalkeySizein bits (default 256).
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
deriveAesKey(
FortisEcdhPublicKey publicKey, {Uint8List? salt, Uint8List? info}) → FortisAesKey -
Derives a ready-to-use FortisAesKey from the ECDH shared secret
with
publicKey. -
deriveKey(
FortisEcdhPublicKey publicKey, {Uint8List? salt, Uint8List? info}) → Uint8List -
Derives raw key bytes from the ECDH shared secret with
publicKey. -
Computes the raw ECDH shared secret with the given
publicKey. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
hkdf(
int keySize = 256, Uint8List? salt, Uint8List? info}) → Uint8List - Derives key bytes from an arbitrary shared secret using HKDF-SHA256 (RFC 5869).
-
hkdfDeriveAesKey(
int keySize = 256, Uint8List? salt, Uint8List? info}) → FortisAesKey - Derives a FortisAesKey from an arbitrary shared secret using HKDF-SHA256.