hash method
Computes hash from input string using specified algorithm.
@param input string which to compute hash from @param signatureAlgorithm algorithm to use for computing hash (supports only SHA-1 and SHA-256) @return array of bytes of computed hash value
Implementation
List<int>? hash(String input, String signatureAlgorithm) {
Digest? result;
var bytes = utf8.encode(input);
if (signatureAlgorithm == "MD5") {
result = md5.convert(bytes);
}
if (signatureAlgorithm == "SHA-1") {
result = sha1.convert(bytes);
}
if (signatureAlgorithm == "SHA-224") {
result = sha224.convert(bytes);
}
if (signatureAlgorithm == "SHA-256") {
result = sha256.convert(bytes);
}
if (signatureAlgorithm == "SHA-384") {
result = sha384.convert(bytes);
}
if (signatureAlgorithm == "SHA-512") {
result = sha512.convert(bytes);
}
return (result != null) ? result.bytes : null;
}