How to hash SHA-512 in Dart

In this Dart tutorial we show you how to use the crypto library in Dart to perform SHA-512 hashing in a Dart program.

Install crypto package in Dart or Flutter

To use the crypto package with Dart, run the following command.

dart pub add crypto

To use the crypto package with Flutter, run the following command.

flutter pub add crypto

The package can be added to your pubspec.yaml as below.

dependencies: 
  crypto: ^3.0.1

How to hash SHA-512 in Dart

In the following Dart program, we use the crypto package to perform SHA-512 hashing which input as a string and return hexadecimal digits string as a result of hashing function.

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

void main() {
  var dataToHash = 'toricode.com';

  var bytesToHash = utf8.encode(dataToHash);
  var sha512Digest = sha512.convert(bytesToHash);

  print('Data to hash: $dataToHash');
  print('SHA-512: $sha512Digest');
}
The output as below.
Data to hash: toricode.com
SHA-512: f0023f2f5dd64efc3090b35cda865fc590fc7831f37c67dbd9a2b8397a4cdcc3c305ed06b4ccb8daaea5293d436d79b577117550693e75c640bbf85d2080445c

Happy Coding 😊

How to Hash SHA-1 in Dart

How to hash SHA-224 in Dart

How to hash SHA-256 in Dart

How to hash SHA-384 in Dart

How to hash MD5 in Dart