Fixes a invalid length hash due to the way dart outputs hex
This commit is contained in:
parent
b2f12eae15
commit
9348bf1370
2 changed files with 11 additions and 3 deletions
|
@ -7,7 +7,7 @@ class Hashing {
|
||||||
var hash = md5.convert(utf8.encode(input)).bytes;
|
var hash = md5.convert(utf8.encode(input)).bytes;
|
||||||
String x = "";
|
String x = "";
|
||||||
for (int byte in hash) {
|
for (int byte in hash) {
|
||||||
x += byte.toRadixString(16);
|
x += byte.toRadixString(16).padLeft(2, '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
|
@ -17,7 +17,7 @@ class Hashing {
|
||||||
var hash = sha1.convert(utf8.encode(input)).bytes;
|
var hash = sha1.convert(utf8.encode(input)).bytes;
|
||||||
String x = "";
|
String x = "";
|
||||||
for (int byte in hash) {
|
for (int byte in hash) {
|
||||||
x += byte.toRadixString(16);
|
x += byte.toRadixString(16).padLeft(2, '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
|
@ -27,7 +27,7 @@ class Hashing {
|
||||||
var hash = sha256.convert(utf8.encode(input)).bytes;
|
var hash = sha256.convert(utf8.encode(input)).bytes;
|
||||||
String x = "";
|
String x = "";
|
||||||
for (int byte in hash) {
|
for (int byte in hash) {
|
||||||
x += byte.toRadixString(16);
|
x += byte.toRadixString(16).padLeft(2, '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
|
|
8
test/hash_test.dart
Normal file
8
test/hash_test.dart
Normal 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");
|
||||||
|
});
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue