Skip to content

Instantly share code, notes, and snippets.

@jokecamp
Created January 17, 2014 17:24
Show Gist options
  • Save jokecamp/8477500 to your computer and use it in GitHub Desktop.
Save jokecamp/8477500 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 hmac = new HMAC(new SHA256(), secretBytes);
hmac.add(messageBytes);
var digest = hmac.close();
var hash = CryptoUtils.bytesToBase64(digest);
// output to html page
querySelector('#hash').text = hash;
// hash => qnR8UCqJggD55PohusaBNviGoOJ67HC6Btry4qXLVZc=
}
@jokecamp
Copy link
Author

Thanks for the heads up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment