Created
January 17, 2014 17:24
-
-
Save jokecamp/8477500 to your computer and use it in GitHub Desktop.
Dart HMAC SHA 256 Example code
This file contains 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: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= | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the heads up