Created
November 5, 2015 03:20
-
-
Save azenla/3dfcaf16a045c0710cd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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