惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
云风的 BLOG
云风的 BLOG
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Hacker News
The Hacker News
Martin Fowler
Martin Fowler
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
U
Unit 42
F
Full Disclosure
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recorded Future
Recorded Future
Security Archives - TechRepublic
Security Archives - TechRepublic
阮一峰的网络日志
阮一峰的网络日志
T
Threatpost
P
Privacy International News Feed
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
I
Intezer
Recent Announcements
Recent Announcements
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Privacy & Cybersecurity Law Blog
A
Arctic Wolf
博客园 - 聂微东
博客园 - 叶小钗
Cisco Talos Blog
Cisco Talos Blog
H
Help Net Security
S
Schneier on Security
Y
Y Combinator Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
The Exploit Database - CXSecurity.com
T
Tor Project blog
月光博客
月光博客
NISL@THU
NISL@THU
A
About on SuperTechFans
Spread Privacy
Spread Privacy
Blog — PlanetScale
Blog — PlanetScale
D
DataBreaches.Net
雷峰网
雷峰网
C
CXSECURITY Database RSS Feed - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
G
Google Developers Blog
W
WeLiveSecurity
P
Palo Alto Networks Blog
The Last Watchdog
The Last Watchdog
K
Kaspersky official blog
博客园 - 司徒正美
L
LINUX DO - 热门话题
小众软件
小众软件

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
SHA-2 Hash Functions in Dart
Mathieu Kerjouan · 2026-06-15 · via DEV Community

Hash functions are one way functions, they are taking an input and will return always the same output based on the input. One of the one used hash function is SHA-256, which is part of the SHA-2 FIPS 180-4 specification. You already know it if you are using Bitcoin and many other crypto-currencies/blockchains. Unfortunately, there are no cryptographic library implementation directly available in the Dart SDK, and we must use external packages.

Instead of re-implementing our own, we will use external packages. At this time, two packages look promising, cryptography , crypto, hashlib and hash, sodium.

Let start with a new sandbox project and compare each ones.

$ dart create hashing
Creating hashing using template console...

  .gitignore
  analysis_options.yaml
  CHANGELOG.md
  pubspec.yaml
  README.md
  bin/hashing.dart
  lib/hashing.dart
  test/hashing_test.dart

Running pub get...                     |-0.8s
  Resolving dependencies...
  Downloading packages...
  Changed 48 dependencies!
  1 package has newer versions incompatible with dependency constraints.
  Try `dart pub outdated` for more information.

Created project hashing in hashing! In order to get started, run the following commands:

  cd hashing
  dart run

$ cd hashing

This program should be simple, the idea is to return a hash from stdin as hexacimal string. This kind of program already exists and are installed by default on probably all Linux distribution via the shasum.

$ echo test | sha224
52f1bf093f4b7588726035c176c0cdb4376cfea53819f1395ac9e6ec  -

$ echo test | sha256sum
f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2  -

$ echo test | sha384sum 
109bb6b5b6d5547c1ce03c7a8bd7d8f80c1cb0957f50c4f7fda04692079917e4f9cad52b878f3d8234e1a170b154b72d  -

$ echo test | sha512sum 
0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123  -

Or it can also be done using OpenSSL or LibreSSL.

$ echo test | openssl dgst -hex -sha224
SHA2-224(stdin)= 52f1bf093f4b7588726035c176c0cdb4376cfea53819f1395ac9e6ec

$ echo test | openssl dgst -hex -sha256
SHA2-256(stdin)= f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2

$ echo test | openssl dgst -hex -sha384
SHA2-384(stdin)= 109bb6b5b6d5547c1ce03c7a8bd7d8f80c1cb0957f50c4f7fda04692079917e4f9cad52b878f3d8234e1a170b154b72d

$ echo test | openssl dgst -hex -sha512
SHA2-512(stdin)= 0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123

The behavior should be the same, except it will use stdin by default and simply print the hash in hexadecimal without other information.

lib/crypto.dart Interface

The crypto package supports only Hash function, including SHA-2 (SHA-224, SHA-256, SHA-384, SHA-512). Few examples are available from its repository. This package is maintained by the Dart Team and is including as core module. Let add it in our project to see what kind of dependencies it requires.

$ dart pub add crypto
"crypto" is already in "dependencies". Will try to update the constraint.
Resolving dependencies... 
Downloading packages... 
  package_config 2.2.0 (3.0.0 available)
Got dependencies!
1 package has newer versions incompatible with dependency constraints.
Try `dart pub outdated` for more information.

import 'dart:convert';
import 'package:crypto/crypto.dart' as crypto;

Future<List<int>> sha224(List<int> input) async {
  return _hash(input, crypto.sha224);
}

Future<List<int>> sha256(List<int> input) async {
  return _hash(input, crypto.sha256);
}

Future<List<int>> sha384(List<int> input) async {
  return _hash(input, crypto.sha384);
}

Future<List<int>> sha512(List<int> input) async {
  return _hash(input, crypto.sha512);
}

Future<List<int>> _hash(List<int> input, dynamic callback) async {
  return callback.convert(input).bytes;
}

lib/cryptography.dart Interface

The cryptography package is supporting all version of SHA-2 (SHA-224, SHA-256, SHA-384 and SHA-512). It does not require a lot of dependencies and seem to be used by a lot of projects. Few examples can be found. Let add it as dependency in our project.

$ dart pub add cryptography
Resolving dependencies... 
Downloading packages... 
+ cryptography 2.9.0
+ ffi 2.2.0
  package_config 2.2.0 (3.0.0 available)
Changed 2 dependencies!
1 package has newer versions incompatible with dependency constraints.
Try `dart pub outdated` for more information.

import 'dart:convert';
import 'dart:async';
import 'package:cryptography/cryptography.dart';

To make things easier, the module lib/cryptography.dart will export 4 functions called sha224(), sha256(), sha384() and sha512(). All of them will take a List<int> as input and will return a Future<List<int>> as output. The next modules will follow the same pattern.

Future<List<int>> sha224(List<int> input) async {
  return _hash(input, Sha224());
}

Future<List<int>> sha256(List<int> input) async {
  return _hash(input, Sha256());
}

Future<List<int>> sha384(List<int> input) async {
  return _hash(input, Sha384());
}

Future<List<int>> sha512(List<int> input) async {
  return _hash(input, Sha512());
}

An object for each kind of hash function must be instantiated first. To avoid duplicated and annoying code, the private function _hash() was created. The first argument is the input as List<int> and the second argument is the instantiated object (all hash objects are using the same methods).

Future<List<int>> _hash(List<int> input, dynamic algorithm) async {
  final sink = algorithm.newHashSink();
  sink.add(input);
  sink.close();
  final hash = await sink.hash();
  return hash.bytes;
}

The implementation can use a synchronous or an asynchronous method to hash the data. In our case, we are using the asynchronous with the help of a Stream and a sink. The sink is created with the help of newHashSink() method

lib/hashlib.dart Interface

$ dart pub add hashlib
Resolving dependencies... 
Downloading packages... 
+ hashlib 2.3.4
+ hashlib_codecs 3.1.2
  package_config 2.2.0 (3.0.0 available)
Changed 2 dependencies!
1 package has newer versions incompatible with dependency constraints.
Try `dart pub outdated` for more information.

Let edit lib/hashlib.dart. Firstly, we need to import the hashlib module.

import 'dart:convert';
import 'package:hashlib/hashlib.dart' as hashlib;

Then, we will reuse the same kind of interface as functions we created before.

Future<String> sha224(List<int> input) async {
  return _hash(input, hashlib.sha224);
}

Future<String> sha256(List<int> input) async {
  return _hash(input, hashlib.sha256);
}

Future<String> sha384(List<int> input) async {
  return _hash(input, hashlib.sha384);
}

Future<String> sha512(List<int> input) async {
  return _hash(input, hashlib.sha512);
}

Finally, we will create our _hash() function. This time, the second argument is waiting for an object callback from hashlib.

Future<String> _hash(List<int> input, dynamic callback) async {
  final s = Stream.fromIterable(input);
  final digest = await callback.byteStream(s);
  return digest.toString();
}

The callback reads the list of integer with the help of the byteStream() method and returns a Future<String> instead of a List<int>. I don't think it was necessary to convert it, it would have been slower for no real benefit.

lib/sodium.dart Interface

The libsodium library supports SHA-2 but the sodium package in Dart does not support it algorithms for now. Let just add it anyway just to see the list of dependency required.

$ dart pub add sodium
Resolving dependencies... 
Downloading packages... 
+ archive 4.0.9
+ code_assets 1.0.0 (1.2.1 available)
+ csslib 1.0.2
+ freezed_annotation 3.1.0
+ hooks 1.0.3 (2.0.2 available)
+ html 0.15.6
+ json_annotation 4.12.0
  package_config 2.2.0 (3.0.0 available)
+ posix 6.5.0
+ record_use 0.6.0
+ sodium 4.0.2+1
Changed 10 dependencies!
3 packages have newer versions incompatible with dependency constraints.
Try `dart pub outdated` for more information.

So, instead of SHA-2, it offers an implementation of Blake2b via the GenericHash class. Sadly, I was expecting a lot from this module because I've already used NaCl and libsodium in the past.

Entry-point bin/hashing.dart

The main entry-point is defined in bin/hashing.dart. Let import few modules first.

import 'dart:io';
import 'dart:convert';
import 'dart:async';
import 'package:hashing/cryptography.dart' as cryptography;
import 'package:hashing/crypto.dart' as crypto;
import 'package:hashing/hashlib.dart' as hashlib;

It will be a command line tool, an usage() function can be nice to have.

int usage() {
  print("usage: hashing HASH MODULE");
  return 1;
}

More than half of the functions created will return a List<int> and did not find a way to convert that in hexadecimal string in the SDK. To fix that, the toHex() function will convert each integers present in the list as 8 bits hexadecimal string and join them. I don't know also if a Dart offers a way to identify the default endianness of the system, a parameter called little has been created to deal with that. It assumes the data are in little-endian and will convert them to big-endian.

String toHex(List<int> bytes, {bool little = true}) {
  return bytes
    .map((i) {
      final int left = i & 0x0f;
      final int right = i >> 4;
      if (little = true)
        return hex(right) + hex(left);
      else
        return hex(left) + hex(right);
    })
    .join();
}

The hex() function is converting an integer to its hexadecimal representation as String. This is a simple switch/case and throwing an error if the integer is not present in the statement.

String hex(int i) {
 switch (i) {
  case 0: return "0";
  case 1: return "1";
  case 2: return "2";
  case 3: return "3";
  case 4: return "4";
  case 5: return "5";
  case 6: return "6";
  case 7: return "7";
  case 8: return "8";
  case 9: return "9";
  case 10: return "a";
  case 11: return "b";
  case 12: return "c";
  case 13: return "d";
  case 14: return "e";
  case 15: return "f";
  default: throw("error");
 }
}

The arguments passed to the program must be "parsed". Again, a simple switch/case will do the job. At least, everybody can easily understand what I want to do there.

Future<String> switcher(List<int> bytes, List<String> args) async {
  switch (args) {
    case ["sha224", "cryptography"]: 
      return toHex(await cryptography.sha224(bytes));
    case ["sha256", "cryptography"]: 
      return toHex(await cryptography.sha256(bytes));
    case ["sha384", "cryptography"]: 
      return toHex(await cryptography.sha384(bytes));
    case ["sha512", "cryptography"]: 
      return toHex(await cryptography.sha512(bytes));

    case ["sha224", "crypto"]: 
      return toHex(await crypto.sha224(bytes));
    case ["sha256", "crypto"]: 
      return toHex(await crypto.sha256(bytes));
    case ["sha384", "crypto"]: 
      return toHex(await crypto.sha384(bytes));
    case ["sha512", "crypto"]: 
      return toHex(await crypto.sha512(bytes));

    case ["sha224", "hashlib"]: 
      return await hashlib.sha224(bytes);
    case ["sha256", "hashlib"]: 
      return await hashlib.sha256(bytes);
    case ["sha384", "hashlib"]:     
      return await hashlib.sha384(bytes);
    case ["sha512", "hashlib"]: 
      return await hashlib.sha512(bytes);

    default:
      return "";
  }
}

Finally, the main() function, reading the input from stdin and forwarding it to the switcher() function.

Future<int> main(List<String> args) async {
  final bytes = (await stdin.toList())[0];
  String digest = await switcher(bytes, args);
  if (digest != "")            
    print(digest);      
    return 0;                         
  return usage();
} 

Test

Let build this project and test it.

$ dart build cli
The `dart build cli` command is in preview at the moment.
See documentation on https://dart.dev/interop/c-interop#native-assets.

Deleting output directory: /tmp/dart/hashing/build/cli/linux_x64/.
Running build hooks... 
Running link hooks... 
Copying 1 build assets:
package:sodium/libsodium
Generated: /tmp/dart/hashing/build/cli/linux_x64/bundle/bin/hashing

Are you lazy? That's my case today. We will use xargs to do most of the jobs for us.

$ printf "cryptography\ncrypto\nhashlib\n" \
  | xargs -I%i sh -c 'echo %i: $(echo test | ./build/cli/linux_x64/bundle/bin/hashing sha224 %i)'
cryptography: 52f1bf093f4b7588726035c176c0cdb4376cfea53819f1395ac9e6ec
crypto: 52f1bf093f4b7588726035c176c0cdb4376cfea53819f1395ac9e6ec
hashlib: 52f1bf093f4b7588726035c176c0cdb4376cfea53819f1395ac9e6ec

$ printf "cryptography\ncrypto\nhashlib\n" 8
  | xargs -I%i sh -c 'echo %i: $(echo test | ./build/cli/linux_x64/bundle/bin/hashing sha256 %i)'
cryptography: f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2
crypto: f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2
hashlib: f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2

$ printf "cryptography\ncrypto\nhashlib\n" \
  | xargs -I%i sh -c 'echo %i: $(echo test | ./build/cli/linux_x64/bundle/bin/hashing sha384 %i)'
cryptography: 109bb6b5b6d5547c1ce03c7a8bd7d8f80c1cb0957f50c4f7fda04692079917e4f9cad52b878f3d8234e1a170b154b72d
crypto: 109bb6b5b6d5547c1ce03c7a8bd7d8f80c1cb0957f50c4f7fda04692079917e4f9cad52b878f3d8234e1a170b154b72d
hashlib: 109bb6b5b6d5547c1ce03c7a8bd7d8f80c1cb0957f50c4f7fda04692079917e4f9cad52b878f3d8234e1a170b154b72d

$ printf "cryptography\ncrypto\nhashlib\n" \
  | xargs -I%i sh -c 'echo %i: $(echo test | ./build/cli/linux_x64/bundle/bin/hashing sha512 %i)'
cryptography: 0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123
crypto: 0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123
hashlib: 0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123

The output is identical for all commands. So, it looks good to me.

Performance

The performance difference when a program is executed with the Dart VM and as native application is real. Here a few examples.

$ time echo test | openssl dgst -sha224 -binary | base64
UvG/CT9LdYhyYDXBdsDNtDds/qU4GfE5Wsnm7A==

real    0m0,007s
user    0m0,002s
sys     0m0,007s

$ time echo test | dart run bin/hashing.dart sha224 cryptography
Running build hooks... 
52f1bf093f4b7588726035c176c0cdb4376cfea53819f1395ac9e6ec

real    0m0,944s
user    0m1,343s
sys     0m0,194s

$ time echo test | ./build/cli/linux_x64/bundle/bin/hashing sha224 cryptography
52f1bf093f4b7588726035c176c0cdb4376cfea53819f1395ac9e6ec

real    0m0,007s
user    0m0,000s
sys     0m0,009s

When using the Dart Virtual Machine, the code is taking more than 1 second to hash the string "test". I think its due to the VM initialization or the Dart application trying to see what kind of changes have been made. Anyway, the code generated by Dart in a native format is still a bit slow compared to OpenSSL though.

Conclusion

Choosing a cryptographic library nowadays is hard. 10 years ago, only few projects were available, and most of the time, we were using OpenSSL or one of its fork like LibreSSL. GnuTLS, BearSSL, PolarSSL or WolfSSL were also other alternatives to consider. Instead of reusing the already deeply tested and checked libraries, all "modern languages" decided to reimplement their own.

The Dart team only support the crypto package offering hashing algorithms, but any other cryptographic functions. If you only need hashing, use this one. If you need more, you should probably test cryptography and hashlib packages. Finally, if you don't care about SHA-2 and you just want something portable, you can check libsodium package.


Cover Image by Noah Näf on Unsplash