Fixes a invalid length hash due to the way dart outputs hex

This commit is contained in:
zontreck 2024-05-16 02:59:10 -07:00
parent b2f12eae15
commit 9348bf1370
2 changed files with 11 additions and 3 deletions

View file

@ -7,7 +7,7 @@ class Hashing {
var hash = md5.convert(utf8.encode(input)).bytes;
String x = "";
for (int byte in hash) {
x += byte.toRadixString(16);
x += byte.toRadixString(16).padLeft(2, '0');
}
return x;
@ -17,7 +17,7 @@ class Hashing {
var hash = sha1.convert(utf8.encode(input)).bytes;
String x = "";
for (int byte in hash) {
x += byte.toRadixString(16);
x += byte.toRadixString(16).padLeft(2, '0');
}
return x;
@ -27,7 +27,7 @@ class Hashing {
var hash = sha256.convert(utf8.encode(input)).bytes;
String x = "";
for (int byte in hash) {
x += byte.toRadixString(16);
x += byte.toRadixString(16).padLeft(2, '0');
}
return x;

8
test/hash_test.dart Normal file
View file

@ -0,0 +1,8 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:libac_flutter/utils/Hashing.dart';
void main() {
test("Test md5", () {
expect(Hashing.md5Hash("Hello World"), "b10a8db164e0754105b7a99be72e3fe5");
});
}