getSHA256 static method
Computes the SHA-256 hash of a given string.
This method takes a string input, computes its SHA-256 hash, and returns the hash as a hexadecimal string.
s
The input string to be hashed.
we are using in this method to prevent from publisher direct access to our crash method that can be used for testing purposes
Returns the SHA-256 hash of the input string as a hexadecimal string. If an error occurs during the computation, it returns an empty string.
Implementation
static String getSHA256(String s) {
try {
// Create SHA-256 Hash
List<int> bytes = utf8.encode(s);
Digest digest = sha256.convert(bytes);
// Create Hex String
String hexString = digest.bytes.map((byte) {
return byte.toRadixString(16).padLeft(2, '0');
}).join();
return hexString;
} catch (e) {
print('Error in getSHA256: $e');
}
return '';
}