signString method

Future<Signature> signString(
  1. String message, {
  2. required KeyPair keyPair,
})
inherited

Signs a string.

The string is converted to bytes using utf8 codec.

Example

In this example, we use Ed25519:

import 'package:cryptography/cryptography.dart';

Future<void> main() async {
  final signedMessage = 'Hello, world!';

  final ed25519 = Ed25519();
  final keyPair = await ed25519.newKeyPair();
  final signature = await ed25519.signString(
    signedMessage,
    keyPair: keyPair,
  );

  // ...

  final isRealSignature = await ed25519.verifyString(
    signedMessage,
    signature: signature,
  );

  print('Signature verification result: $isRealSignature');
}

Implementation

Future<Signature> signString(String message, {required KeyPair keyPair}) {
  return sign(
    utf8.encode(message),
    keyPair: keyPair,
  );
}