Ecdh class abstract
ECDH with P-256 / P-384 / P-521 elliptic curve.
Private keys can be instances of EcSecretKey
or implementation-specific
subclasses of SecretKey.
Example
import 'package:better_cryptography/better_cryptography.dart';
Future<void> main() async {
// In this example, we use P-256 curve.
final algorithm = Ecdh.p256();
// Alice generates a key pair for herself.
final aliceSecretKey = await algorithm.newSecretKey();
final alicePublicKey = await algorithm.publicKey(aliceSecretKey);
// Bob generates a key pair for himself.
final bobSecretKey = await algorithm.newSecretKey();
final bobPublicKey = await algorithm.publicKey(bobSecretKey);
// Each party calculates shared secret.
// Parties get the same symmetric key as a result.
final keyForAlice = await algorithm.sharedSecretKey(
localSecretKey: alicePublicKey,
remotePublicKey: bobPublicKey,
);
final keyForBob = await algorithm.sharedSecretKey(
localSecretKey: bobSecretKey,
remotePublicKey: alicePublicKey,
);
}
- Inheritance
- Implementers
Constructors
- Ecdh.constructor()
-
Constructor for classes that extend this class.
const
- Ecdh.p256({required int length})
-
ECDH using P-256 (secp256r1 / prime256v1) elliptic curve.
factory
- Ecdh.p384({required int length})
-
ECDH using P-384 (secp384r1 / prime384v1) elliptic curve.
factory
- Ecdh.p521({required int length})
-
ECDH using P-521 (secp521r1 / prime521v1) elliptic curve.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
keyPairType
→ KeyPairType<
KeyPairData, PublicKey> -
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
newKeyPair(
) → Future< EcKeyPair> -
Generates a new KeyPair for this algorithm.
override
-
newKeyPairFromSeed(
List< int> seed) → Future<EcKeyPair> -
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
Calculates a shared SecretKey.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited