Skip to content

Instantly share code, notes, and snippets.

@azenla
Created November 5, 2015 03:20
Show Gist options
  • Save azenla/3dfcaf16a045c0710cd3 to your computer and use it in GitHub Desktop.
Save azenla/3dfcaf16a045c0710cd3 to your computer and use it in GitHub Desktop.
Future<String> _createRowHash(String tableName, packed, {time, String salt}) async {
if (time == null) {
time = new DateTime.now().millisecondsSinceEpoch;
}
if (time is String) {
time = DateTime.parse(time).millisecondsSinceEpoch;
}
if (time is DateTime) {
time = time.millisecondsSinceEpoch;
}
if (salt == null) {
salt = await generateStrongToken(length: 10);
}
tableName = _createHash(tableName);
packed = _createHash(packed);
time = _createHash(time.toString());
salt = _createHash(salt);
return _createHash("${tableName}-${packed}-${time}-${salt}");
}
String _createHash(input) {
if (input is String) {
input = const Utf8Encoder().convert(input);
}
var sha = new SHA256();
sha.add(input);
return CryptoUtils.bytesToHex(sha.close());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment