Generate MD5 Hash using Dart

Pointy Castle package

  1. Add pointycastle and hex packages to pubspec.yaml file:
dependencies:
  hex: ^0.2.0
  pointycastle: ^3.6.0
  1. Install packages from the command line:
pub get
  1. Generate MD5 hash:
import 'dart:convert';
import 'dart:typed_data';
import "package:hex/hex.dart";
import 'package:pointycastle/pointycastle.dart';

void main() {
  String text = 'Hello';
  var digestObject = Digest('MD5');
  var bytes = digestObject.process(utf8.encode(text) as Uint8List);
  String digest = HEX.encode(bytes);

  print(digest);
}

Leave a Comment

Cancel reply

Your email address will not be published.