Ecdsa class abstract

ECDSA with P-256 / P-384 / P-521 elliptic curve.

For more information about ECDSA, read RFC 6090 ("Fundamental Elliptic Curve Cryptography Algorithms").

Key pairs must be instances of EcKeyPair.

In browsers, the default implementation will use Web Cryptography API. On other platforms, DartEcdsa will be used.

If you use Flutter, you can enable cryptography_flutter. It can improve performance in many cases.

Things to know

Example

import 'package:cryptography/cryptography.dart';

Future<void> main() async {
  // In this example, we use ECDSA-P256-SHA256
  final algorithm = Ecdsa.p256(Sha256());

  // Generate a random key pair
  final secretKey = await algorithm.newSecretKey();
  final publicKey = await algorithm.publicKey(secretKey);

  // Sign a message
  final message = <int>[1,2,3];
  final signature = await algorithm.sign(
    [1,2,3],
    secretKey: secretKey,
  );

  // Anyone can verify the signature
  final isVerified = await algorithm.verify(
    message: message,
    signature: signature,
  );
}
Inheritance
Implementers

Constructors

Ecdsa.constructor()
Constructor for classes that extend this class.
const
Ecdsa.p256(HashAlgorithm hashAlgorithm)
ECDSA using P-256 (secp256r1 / prime256v1) elliptic curve.
factory
Ecdsa.p384(HashAlgorithm hashAlgorithm)
ECDSA using P-384 (secp384r1 / prime384v1) elliptic curve.
factory
Ecdsa.p521(HashAlgorithm hashAlgorithm)
ECDSA using P-521 (secp521r1 / prime521v1) elliptic curve.
factory

Properties

hashAlgorithm HashAlgorithm
Used hash algorithm.
no setter
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>
Generates a new KeyPair that uses the seed bytes.
override
newSignatureWand() Future<SignatureWand>
Generates a new SignatureWand that has a random KeyPair.
inherited
newSignatureWandFromKeyPair(KeyPair keyPair) Future<SignatureWand>
Generates a new SignatureWand that uses the given KeyPair.
inherited
newSignatureWandFromSeed(List<int> seed) Future<SignatureWand>
Generates a new SignatureWand that uses the given seed bytes.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
sign(List<int> message, {required KeyPair keyPair}) Future<Signature>
Signs bytes.
inherited
signString(String message, {required KeyPair keyPair}) Future<Signature>
Signs a string.
inherited
toString() String
A string representation of this object.
override
verify(List<int> message, {required Signature signature}) Future<bool>
Verifies whether bytes was signed with signature.
inherited
verifyString(String message, {required Signature signature}) Future<bool>
Verifies whether a string was signed with signature.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited