Ecdh class abstract
ECDH with P-256 / P-384 / P-521 elliptic curve.
Private keys must be instances of EcKeyPair.
In browsers, the default implementation will use Web Cryptography API. On other platforms, DartEcdh will be used.
If you use Flutter, you can enable cryptography_flutter. It can improve performance in many cases.
Things to know
- Private keys are instances of EcKeyPair.
- Public keys are instances of EcPublicKey.
- You can use package:jwk to encode/decode JSON Web Key (JWK) data.
Example
import 'package:cryptography/cryptography.dart';
Future<void> main() async {
final algorithm = Ecdh.p256();
// We need the private key pair of Alice.
final aliceKeyPair = await algorithm.newKeyPair();
// We need only public key of Bob.
final bobKeyPair = await algorithm.newKeyPair();
final bobPublicKey = await bobKeyPair.extractPublicKey();
// We can now calculate a 32-byte shared secret key.
final sharedSecretKey = await algorithm.sharedSecretKey(
keyPair: aliceKeyPair,
remotePublicKey: bobPublicKey,
);
}
- 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
-
newKeyExchangeWand(
) → Future< KeyExchangeWand> -
Returns a new KeyExchangeWand that has a random KeyPair.
inherited
-
newKeyExchangeWandFromKeyPair(
KeyPair keyPair) → Future< KeyExchangeWand> -
Returns a new KeyExchangeWand that uses the given KeyPair.
inherited
-
newKeyPair(
) → Future< EcKeyPair> -
Generates a new KeyPair that can be used with this algorithm.
override
-
newKeyPairFromSeed(
List< int> seed) → Future<EcKeyPair> -
Generates a key pair from the seed.
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