hash function
Create a hash digest from the data with an hash algorithm identification prepending the digest @param {String | Uint8List} content Data to hash (string or buffer) @param {String} algo Hash algorithm ("sha256", "sha512", "sha3-256", "sha3-512", "blake2b")
Implementation
Uint8List hash(dynamic content, {String algo = 'sha256'}) {
if (content is! Uint8List && content is! String) {
throw "'content' must be a string or Uint8List";
}
if (content is String) {
if (isHex(content)) {
content = Uint8List.fromList(utf8.encode(content));
} else {
content = Uint8List.fromList(content.codeUnits);
}
}
final algoID = hashAlgoToID(algo);
final digest = getHashDigest(content, algo);
return concatUint8List(<Uint8List>[
Uint8List.fromList(<int>[algoID]),
digest
]);
}