Ed25519 class abstract

Ed25519 (RFC 8032) signature algorithm.

By default, DartEd25519 will be used. If you use Flutter, you can enable cryptography_flutter. It can improve performance in many cases.

Things to know

  • Private key is any 32 bytes (SimpleKeyPair).
  • Public key is 32 bytes (SimplePublicKey).
  • Output is 32 bytes.
  • RFC 8032 says that the signatures are deterministic, but some widely used implementations such as Apple CryptoKit return non-deterministic signatures.
  • 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 = Ed25519();

  // Generate a key pair
  final keyPair = await algorithm.newKeyPair();

  // Sign a message
  final message = <int>[1,2,3];
  final signature = await algorithm.sign(
    message,
    keyPair: keyPair,
  );
  print('Signature bytes: ${signature.bytes}');
  print('Public key: ${signature.publicKey.bytes}');

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

In need of synchronous APIs?

If you need to perform operations synchronously, use DartEd25519 in package:cryptography/dart.dart.

Inheritance
Implementers

Constructors

Ed25519()
factory
Ed25519.constructor({Random? random})
Constructor for classes that extend this class.
const

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<SimpleKeyPair>
Generates a new KeyPair for this algorithm.
override
newKeyPairFromSeed(List<int> seed) Future<SimpleKeyPair>
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