Skip to content

Instantly share code, notes, and snippets.

@majindageta
Forked from jokecamp/example.dart
Last active November 29, 2022 06:45
Show Gist options
  • Save majindageta/2bbb1866a60717fa6c64f5ff2d8b280f to your computer and use it in GitHub Desktop.
Save majindageta/2bbb1866a60717fa6c64f5ff2d8b280f to your computer and use it in GitHub Desktop.
Dart HMAC SHA 256 Example code
import 'dart:html';
import 'dart:convert';
import 'package:crypto/crypto.dart';
void main() {
String secret = 'secret';
String message = 'Message';
List<int> secretBytes = utf8.encode(secret);
List<int> messageBytes = utf8.encode(message);
var hMacSha256 = new Hmac(sha256, secretBytes);
var hash = hMacSha256.convert(messageBytes);
// output to html page
querySelector('#hash').text = hash;
// hash => qnR8UCqJggD55PohusaBNviGoOJ67HC6Btry4qXLVZc=
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment