getHashPlain static method

Uint8List getHashPlain(
  1. Uint8List bytes, {
  2. String algorithmName = 'SHA-256',
})

Get a hash for the given bytes using the given algorithm

The default algorithm used is SHA-256. All supported algorihms are :

  • SHA-1
  • SHA-224
  • SHA-256
  • SHA-384
  • SHA-512
  • SHA-512/224
  • SHA-512/256
  • MD5

Implementation

static Uint8List getHashPlain(Uint8List bytes,
    {String algorithmName = 'SHA-256'}) {
  Uint8List hash;
  switch (algorithmName) {
    case 'SHA-1':
      hash = Digest('SHA-1').process(bytes);
      break;
    case 'SHA-224':
      hash = Digest('SHA-224').process(bytes);
      break;
    case 'SHA-256':
      hash = Digest('SHA-256').process(bytes);
      break;
    case 'SHA-384':
      hash = Digest('SHA-384').process(bytes);
      break;
    case 'SHA-512':
      hash = Digest('SHA-512').process(bytes);
      break;
    case 'SHA-512/224':
      hash = Digest('SHA-512/224').process(bytes);
      break;
    case 'SHA-512/256':
      hash = Digest('SHA-512/256').process(bytes);
      break;
    case 'MD5':
      hash = Digest('MD5').process(bytes);
      break;
    default:
      throw ArgumentError('Hash not supported');
  }

  return hash;
}