1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
enum CryptoType {
sha1,
sha224,
sha256,
sha384,
sha512,
sha512_224,
sha512_256,
md5,
}
class CryptoPage extends StatefulWidget {
final String title;
const CryptoPage({super.key, required this.title});
@override
State<CryptoPage> createState() => _CryptoPageState();
}
class _CryptoPageState extends State<CryptoPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Column(
children: [
ElevatedButton(
onPressed: () => _hashString('hello world', CryptoType.sha1),
child: const Text('sha1')),
const SizedBox(
height: 20,
),
ElevatedButton(
onPressed: () => _hashString('hello world', CryptoType.sha224),
child: const Text('sha224')),
const SizedBox(
height: 20,
),
ElevatedButton(
onPressed: () => _hashString('hello world', CryptoType.sha256),
child: const Text('sha256')),
const SizedBox(
height: 20,
),
ElevatedButton(
onPressed: () => _hashString('hello world', CryptoType.sha384),
child: const Text('sha384')),
const SizedBox(
height: 20,
),
ElevatedButton(
onPressed: () => _hashString('hello world', CryptoType.sha512),
child: const Text('sha512')),
const SizedBox(
height: 20,
),
ElevatedButton(
onPressed: () =>
_hashString('hello world', CryptoType.sha512_224),
child: const Text('sha512_224')),
const SizedBox(
height: 20,
),
ElevatedButton(
onPressed: () =>
_hashString('hello world', CryptoType.sha512_256),
child: const Text('sha512_256')),
const SizedBox(
height: 20,
),
ElevatedButton(
onPressed: () => _hashString('hello world', CryptoType.md5),
child: const Text('md5')),
const SizedBox(
height: 20,
),
],
),
),
);
}
String _hashString(String text, CryptoType type) {
if (text.isEmpty) {
return '';
}
var bytes = utf8.encode(text); // data being hashed
var res = '';
switch (type) {
case CryptoType.sha1:
res = sha1.convert(bytes).toString();
break;
case CryptoType.sha224:
res = sha224.convert(bytes).toString();
break;
case CryptoType.sha256:
res = sha256.convert(bytes).toString();
break;
case CryptoType.sha384:
res = sha384.convert(bytes).toString();
break;
case CryptoType.sha512:
res = sha512.convert(bytes).toString();
break;
case CryptoType.sha512_224:
res = sha512224.convert(bytes).toString();
break;
case CryptoType.sha512_256:
res = sha512256.convert(bytes).toString();
break;
case CryptoType.md5:
res = md5.convert(bytes).toString();
break;
default:
}
debugPrint('_hashString:$res');
return res;
}
}
|