Created
June 7, 2022 06:46
-
-
Save AlexV525/970e16237b1f96715ca09675e1c6b4ab to your computer and use it in GitHub Desktop.
Signer for Lark webhooks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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