Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 hmac = new HMAC(new SHA256(), secretBytes);
var digest = hmac.close();
var hash = CryptoUtils.bytesToBase64(digest);
// output to html page
querySelector('#hash').text = hash;
// hash => qnR8UCqJggD55PohusaBNviGoOJ67HC6Btry4qXLVZc=

This comment has been minimized.

Copy link

@majindageta majindageta commented Apr 14, 2020

Hi, I've forked your code and updated it.
You are the first result on google and the code doesn't work because the lib has been updated several times.
Have a nice day!


This comment has been minimized.

Copy link
Owner Author

@jokecamp jokecamp commented Apr 14, 2020

Thanks for the heads up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.