Skip to content

Instantly share code, notes, and snippets.

@AlexV525
Created June 7, 2022 06:46
Show Gist options
  • Save AlexV525/970e16237b1f96715ca09675e1c6b4ab to your computer and use it in GitHub Desktop.
Save AlexV525/970e16237b1f96715ca09675e1c6b4ab to your computer and use it in GitHub Desktop.
Signer for Lark webhooks
import 'dart:convert';
import 'package:crypto/crypto.dart';
Map<String, String> sign({
required String key,
DateTime? dateTime,
}) {
dateTime ??= DateTime.now();
final int timestamp = dateTime.millisecondsSinceEpoch ~/ 1000;
final Hmac signKey = Hmac(sha256, utf8.encode('$timestamp\n$key'));
final Digest digest = signKey.convert(<int>[]);
final String sign = base64.encode(digest.bytes);
return <String, String>{'timestamp': '$timestamp', 'sign': sign};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment