hashlib 1.6.0 copy "hashlib: ^1.6.0" to clipboard
hashlib: ^1.6.0 copied to clipboard

Secure hash functions, checksum generators, and key derivation algorithms optimized for Dart.

hashlib #

plugin version dependencies dart support likes pub points popularity test

This library contains implementations of secure hash functions, checksum generators, and key derivation algorithms optimized for Dart.

Features #

Secure Hash Functions #

Algorithm Available Methods Source
MD5 md5 RFC-1321
SHA-1 sha1 RFC-3174
SHA-2 sha224,sha256,sha384,sha512, sha512t224, sha512t256 RCC-6234
SHA-3 sha3_224,sha3_256,sha3_384,sha3_512, shake128, shake256 FIPS-202
Keccak keccak224,keccak256,keccak384,keccak512 Team Keccak
Blake2b blake2b160,blake2b256,blake2b384, blake2b512 RFC-7693
Blake2s blake2s128,blake2s160,blake2s224,blake2s256 RFC-7693

Password Hashing / Key Derivation #

Algorithm Available Methods Source
Argon2 argon2d, argon2i, argon2id RFC-9106

Message Authentication Code (MAC) generators #

Algorithms Available Methods Source
HMAC hmac RFC-2104

Checksum Algorithms #

Algorithms Available Methods Source
Alder32 alder32 Wikipedia
CRC crc16,crc32,crc64 Wikipedia

Getting Started #

The following import will give you access to all of the algorithms in this package.

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

Check the API Reference for details.

Usage #

Examples can be found inside the example folder.

import 'package:hashlib/hashlib.dart';

void main() {
  // Examples of Hash generation
  var text = "Happy Hashing!";
  print('[CRC32] $text => ${crc32code(text)}');
  print('[CRC64] $text => ${crc64code(text)}');
  print('[MD5] $text => ${md5sum(text)}');
  print('[SHA-1] $text => ${sha1sum(text)}');
  print('[SHA-224] $text => ${sha224sum(text)}');
  print('[SHA-256] $text => ${sha256sum(text)}');
  print('[SHA-384] $text => ${sha384sum(text)}');
  print('[SHA-512] $text => ${sha512sum(text)}');
  print('[SHA-512/224] $text => ${sha512t224sum(text)}');
  print('[SHA-512/256] $text => ${sha512t256sum(text)}');
  print('[SHA3-224] $text => ${sha3_224sum(text)}');
  print('[SHA3-256] $text => ${sha3_256sum(text)}');
  print('[SHA3-384] $text => ${sha3_384sum(text)}');
  print('[SHA3-512] $text => ${sha3_512sum(text)}');
  print('[Keccak-224] $text => ${keccak224sum(text)}');
  print('[Keccak-256] $text => ${keccak256sum(text)}');
  print('[Keccak-384] $text => ${keccak384sum(text)}');
  print('[Keccak-512] $text => ${keccak512sum(text)}');
  print('[SHAKE-128] $text => ${shake128sum(text, 20)}');
  print('[SHAKE-256] $text => ${shake256sum(text, 20)}');
  print('[BLAKE-2s/256] $text => ${blake2s256.string(text)}');
  print('[BLAKE-2b/512] $text => ${blake2b512.string(text)}');
  print('');

  // Example of HMAC generation
  var key = "secret";
  print('HMAC[MD5] $text => ${md5.hmacBy(key).string(text)}');
  print('HMAC[SHA-1] $text => ${sha1.hmacBy(key).string(text)}');
  print('HMAC[SHA-256] $text => ${sha256.hmacBy(key).string(text)}');
  print('');

  // Example of Argon2 Password Hashing
  print("Argon2id encoded: ${argon2id(
    "password".codeUnits,
    "some salt".codeUnits,
    security: Argon2Security.small,
    hashLength: 16,
  ).encoded()}");
}

Benchmarks #

To obtain the following benchmarks, run this command:

dart run ./benchmark/benchmark.dart

Libraries:

With string of length 10 (100000 iterations):

Algorithms hashlib crypto hash PointyCastle sha3
MD5 35.353 ms 99.184 ms
181% slower
132.232 ms
274% slower
84.348 ms
139% slower
SHA-1 60.984 ms 115.06 ms
89% slower
204.618 ms
236% slower
132.707 ms
118% slower
SHA-224 82.921 ms 137.013 ms
65% slower
376.467 ms
354% slower
317.903 ms
283% slower
SHA-256 82.724 ms 135.03 ms
63% slower
375.416 ms
354% slower
318.855 ms
285% slower
SHA-384 103.835 ms 344.046 ms
231% slower
722.537 ms
596% slower
2601.015 ms
2405% slower
SHA-512 103.755 ms 346.637 ms
234% slower
713.643 ms
588% slower
2627.374 ms
2432% slower
SHA-512/224 102.017 ms 342.321 ms
236% slower
5106.248 ms
4905% slower
SHA-512/256 102.386 ms 341.22 ms
233% slower
5096.226 ms
4877% slower
SHA3-256 82.077 ms 4472.259 ms
5349% slower
408.232 ms
397% slower
SHA3-512 103.6 ms 4481.2 ms
4225% slower
408.795 ms
295% slower
BLAKE-2s 62.667 ms
BLAKE-2b 81.948 ms 1144.464 ms
1297% slower
HMAC(MD5) 213.07 ms 266.102 ms
25% slower
498.219 ms
134% slower
HMAC(SHA-256) 535.764 ms 624.437 ms
17% slower

With string of length 1000 (5000 iterations):

Algorithms hashlib crypto hash PointyCastle sha3
MD5 31.268 ms 41.928 ms
34% slower
52.334 ms
67% slower
60.301 ms
93% slower
SHA-1 36.819 ms 53.565 ms
45% slower
105.095 ms
185% slower
89.969 ms
144% slower
SHA-224 52.821 ms 63.124 ms
20% slower
238.791 ms
352% slower
237.553 ms
350% slower
SHA-256 52.85 ms 62.812 ms
19% slower
238.127 ms
351% slower
236.949 ms
348% slower
SHA-384 34.541 ms 107.518 ms
211% slower
257.815 ms
646% slower
1000.244 ms
2796% slower
SHA-512 33.865 ms 107.616 ms
218% slower
233.219 ms
589% slower
999.335 ms
2851% slower
SHA-512/224 33.684 ms 109.742 ms
226% slower
1123.899 ms
3237% slower
SHA-512/256 34.84 ms 109.424 ms
214% slower
1143.562 ms
3182% slower
SHA3-256 54.081 ms 1721.936 ms
3084% slower
230.092 ms
325% slower
SHA3-512 34.698 ms 3002.732 ms
8554% slower
337.325 ms
872% slower
BLAKE-2s 36.763 ms
BLAKE-2b 25.799 ms 409.533 ms
1487% slower
HMAC(MD5) 40.644 ms 53.016 ms
30% slower
70.384 ms
73% slower
HMAC(SHA-256) 74.654 ms 91.42 ms
22% slower

With string of length 500000 (10 iterations):

Algorithms hashlib crypto hash PointyCastle sha3
MD5 30.376 ms 40.509 ms
33% slower
69.67 ms
129% slower
57.96 ms
91% slower
SHA-1 33.523 ms 51.793 ms
54% slower
120.908 ms
261% slower
86.113 ms
157% slower
SHA-224 50.253 ms 60.678 ms
21% slower
249.619 ms
397% slower
230.563 ms
359% slower
SHA-256 50.344 ms 60.738 ms
21% slower
249.453 ms
395% slower
229.371 ms
356% slower
SHA-384 31.777 ms 103.155 ms
225% slower
280.01 ms
781% slower
968.057 ms
2946% slower
SHA-512 31.718 ms 103.332 ms
226% slower
279.144 ms
780% slower
969.389 ms
2956% slower
SHA-512/224 31.656 ms 102.954 ms
225% slower
970.759 ms
2967% slower
SHA-512/256 32.011 ms 103.348 ms
223% slower
968.022 ms
2924% slower
SHA3-256 50.22 ms 1560.669 ms
3008% slower
212.792 ms
324% slower
SHA3-512 31.7 ms 2932.904 ms
9152% slower
334.856 ms
956% slower
BLAKE-2s 34.788 ms
BLAKE-2b 23.761 ms 393.928 ms
1558% slower
HMAC(MD5) 31.094 ms 42.317 ms
36% slower
69.942 ms
125% slower
HMAC(SHA-256) 50.258 ms 62.296 ms
24% slower

These benchmarks were done in AMD Ryzen 7 5800X processor and 3200MHz RAM using compiled exe on Windows 10

31
likes
0
pub points
89%
popularity

Publisher

verified publisherbitanon.dev

Secure hash functions, checksum generators, and key derivation algorithms optimized for Dart.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on hashlib