Skip to content

A Dart implementation of SHA cryptographic hash functions

Notifications You must be signed in to change notification settings

cycloss/dart-crypto-hash

Repository files navigation

Crypto Hash

The SHA-1 hash function implemented from scratch using pure dart.

I might add support for SHA-256 in the future.

Installing

For now, Crypto Hash is not available through pub dev, but you can still install it by adding the following to your dependencies:

dependencies:
  crypto_hash:
    git:
      url: https://github.com/lucas979797/dart-crypto-hash
      ref: main

Usage

A simple usage example:

import 'dart:convert';

import 'package:crypto_hash/crypto_hash.dart';

void main() {
  
  var hash = ShaOne.hashString('Hello World!');
  print(hash); // prints 2ef7bde68ce5404e97d5f042f95f89f1c232871

  // Unicode:
  var testString2 = 'こんにちは世界!';
  var hash2 = ShaOne.hashBytes(utf8.encode(testString2));
  print(hash2); // prints f66b68c765fae864106c7352d06be5df5ab510c3

  // Hashing a file: (see example directory for lorem.txt)
  var hash3 = ShaOne.hashFile('example/lorem.txt');
  print(hash3); // prints 4b0b2b74dab6099447a0471d6b390ce21055d508
}

Features and bugs

Let me know if you find any...

Other

I built this library to improve my understanding of hashing, and it is my first time implementing a (semi) secure hashing algorithm.

I found the following resources useful for learning:

I enjoyed doing the project in Dart, but if I did it again i'd just do it in C because there is a fair bit of extra manipulation that has to be done in Dart due to the language only supporting 64 bit integers.

About

A Dart implementation of SHA cryptographic hash functions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages