11
11
import java .security .KeyPairGenerator ;
12
12
import java .security .NoSuchAlgorithmException ;
13
13
import java .security .SecureRandom ;
14
- import java .util .Arrays ;
15
14
16
15
import static com .blankj .utilcode .util .TestConfig .PATH_ENCRYPT ;
17
16
import static org .junit .Assert .assertArrayEquals ;
18
17
import static org .junit .Assert .assertEquals ;
19
- import static org .junit .Assert .assertTrue ;
20
18
21
19
22
20
/**
@@ -82,11 +80,9 @@ public void encryptSHA1() {
82
80
blankjSHA1 ,
83
81
EncryptUtils .encryptSHA1ToString ("blankj" .getBytes ())
84
82
);
85
- assertTrue (
86
- Arrays .equals (
87
- hexString2Bytes (blankjSHA1 ),
88
- EncryptUtils .encryptSHA1 ("blankj" .getBytes ())
89
- )
83
+ assertArrayEquals (
84
+ hexString2Bytes (blankjSHA1 ),
85
+ EncryptUtils .encryptSHA1 ("blankj" .getBytes ())
90
86
);
91
87
}
92
88
@@ -101,11 +97,9 @@ public void encryptSHA224() {
101
97
blankjSHA224 ,
102
98
EncryptUtils .encryptSHA224ToString ("blankj" .getBytes ())
103
99
);
104
- assertTrue (
105
- Arrays .equals (
106
- hexString2Bytes (blankjSHA224 ),
107
- EncryptUtils .encryptSHA224 ("blankj" .getBytes ())
108
- )
100
+ assertArrayEquals (
101
+ hexString2Bytes (blankjSHA224 ),
102
+ EncryptUtils .encryptSHA224 ("blankj" .getBytes ())
109
103
);
110
104
}
111
105
@@ -120,12 +114,10 @@ public void encryptSHA256() {
120
114
blankjSHA256 ,
121
115
EncryptUtils .encryptSHA256ToString ("blankj" .getBytes ())
122
116
);
123
- assertTrue (
124
- Arrays .equals (
125
- hexString2Bytes (blankjSHA256 ),
126
- EncryptUtils .encryptSHA256 ("blankj" .getBytes ())
127
- )
128
- );
117
+ assertArrayEquals (
118
+ hexString2Bytes (blankjSHA256 ),
119
+ EncryptUtils .encryptSHA256 ("blankj" .getBytes ()));
120
+
129
121
}
130
122
131
123
@ Test
@@ -139,11 +131,9 @@ public void encryptSHA384() {
139
131
blankjSHA384 ,
140
132
EncryptUtils .encryptSHA384ToString ("blankj" .getBytes ())
141
133
);
142
- assertTrue (
143
- Arrays .equals (
144
- hexString2Bytes (blankjSHA384 ),
145
- EncryptUtils .encryptSHA384 ("blankj" .getBytes ())
146
- )
134
+ assertArrayEquals (
135
+ hexString2Bytes (blankjSHA384 ),
136
+ EncryptUtils .encryptSHA384 ("blankj" .getBytes ())
147
137
);
148
138
}
149
139
@@ -158,11 +148,9 @@ public void encryptSHA512() {
158
148
blankjSHA512 ,
159
149
EncryptUtils .encryptSHA512ToString ("blankj" .getBytes ())
160
150
);
161
- assertTrue (
162
- Arrays .equals (
163
- hexString2Bytes (blankjSHA512 ),
164
- EncryptUtils .encryptSHA512 ("blankj" .getBytes ())
165
- )
151
+ assertArrayEquals (
152
+ hexString2Bytes (blankjSHA512 ),
153
+ EncryptUtils .encryptSHA512 ("blankj" .getBytes ())
166
154
);
167
155
}
168
156
@@ -181,11 +169,9 @@ public void encryptHmacMD5() {
181
169
blankjHmacMD5 ,
182
170
EncryptUtils .encryptHmacMD5ToString ("blankj" .getBytes (), blankjHmackey .getBytes ())
183
171
);
184
- assertTrue (
185
- Arrays .equals (
186
- hexString2Bytes (blankjHmacMD5 ),
187
- EncryptUtils .encryptHmacMD5 ("blankj" .getBytes (), blankjHmackey .getBytes ())
188
- )
172
+ assertArrayEquals (
173
+ hexString2Bytes (blankjHmacMD5 ),
174
+ EncryptUtils .encryptHmacMD5 ("blankj" .getBytes (), blankjHmackey .getBytes ())
189
175
);
190
176
}
191
177
@@ -200,11 +186,9 @@ public void encryptHmacSHA1() {
200
186
blankjHmacSHA1 ,
201
187
EncryptUtils .encryptHmacSHA1ToString ("blankj" .getBytes (), blankjHmackey .getBytes ())
202
188
);
203
- assertTrue (
204
- Arrays .equals (
205
- hexString2Bytes (blankjHmacSHA1 ),
206
- EncryptUtils .encryptHmacSHA1 ("blankj" .getBytes (), blankjHmackey .getBytes ())
207
- )
189
+ assertArrayEquals (
190
+ hexString2Bytes (blankjHmacSHA1 ),
191
+ EncryptUtils .encryptHmacSHA1 ("blankj" .getBytes (), blankjHmackey .getBytes ())
208
192
);
209
193
}
210
194
@@ -219,11 +203,9 @@ public void encryptHmacSHA224() {
219
203
blankjHmacSHA224 ,
220
204
EncryptUtils .encryptHmacSHA224ToString ("blankj" .getBytes (), blankjHmackey .getBytes ())
221
205
);
222
- assertTrue (
223
- Arrays .equals (
224
- hexString2Bytes (blankjHmacSHA224 ),
225
- EncryptUtils .encryptHmacSHA224 ("blankj" .getBytes (), blankjHmackey .getBytes ())
226
- )
206
+ assertArrayEquals (
207
+ hexString2Bytes (blankjHmacSHA224 ),
208
+ EncryptUtils .encryptHmacSHA224 ("blankj" .getBytes (), blankjHmackey .getBytes ())
227
209
);
228
210
}
229
211
@@ -238,11 +220,9 @@ public void encryptHmacSHA256() {
238
220
blankjHmacSHA256 ,
239
221
EncryptUtils .encryptHmacSHA256ToString ("blankj" .getBytes (), blankjHmackey .getBytes ())
240
222
);
241
- assertTrue (
242
- Arrays .equals (
243
- hexString2Bytes (blankjHmacSHA256 ),
244
- EncryptUtils .encryptHmacSHA256 ("blankj" .getBytes (), blankjHmackey .getBytes ())
245
- )
223
+ assertArrayEquals (
224
+ hexString2Bytes (blankjHmacSHA256 ),
225
+ EncryptUtils .encryptHmacSHA256 ("blankj" .getBytes (), blankjHmackey .getBytes ())
246
226
);
247
227
}
248
228
@@ -257,11 +237,9 @@ public void encryptHmacSHA384() {
257
237
blankjHmacSHA384 ,
258
238
EncryptUtils .encryptHmacSHA384ToString ("blankj" .getBytes (), blankjHmackey .getBytes ())
259
239
);
260
- assertTrue (
261
- Arrays .equals (
262
- hexString2Bytes (blankjHmacSHA384 ),
263
- EncryptUtils .encryptHmacSHA384 ("blankj" .getBytes (), blankjHmackey .getBytes ())
264
- )
240
+ assertArrayEquals (
241
+ hexString2Bytes (blankjHmacSHA384 ),
242
+ EncryptUtils .encryptHmacSHA384 ("blankj" .getBytes (), blankjHmackey .getBytes ())
265
243
);
266
244
}
267
245
@@ -275,11 +253,9 @@ public void encryptHmacSHA512() {
275
253
blankjHmacSHA512 ,
276
254
EncryptUtils .encryptHmacSHA512ToString ("blankj" .getBytes (), blankjHmackey .getBytes ())
277
255
);
278
- assertTrue (
279
- Arrays .equals (
280
- hexString2Bytes (blankjHmacSHA512 ),
281
- EncryptUtils .encryptHmacSHA512 ("blankj" .getBytes (), blankjHmackey .getBytes ())
282
- )
256
+ assertArrayEquals (
257
+ hexString2Bytes (blankjHmacSHA512 ),
258
+ EncryptUtils .encryptHmacSHA512 ("blankj" .getBytes (), blankjHmackey .getBytes ())
283
259
);
284
260
}
285
261
@@ -293,73 +269,33 @@ public void encryptHmacSHA512() {
293
269
294
270
@ Test
295
271
public void encryptDES () {
296
- assertTrue (
297
- Arrays .equals (
298
- bytesResDES ,
299
- EncryptUtils .encryptDES (
300
- bytesDataDES ,
301
- bytesKeyDES ,
302
- "DES/ECB/NoPadding" ,
303
- null
304
- )
305
- )
272
+ assertArrayEquals (
273
+ bytesResDES ,
274
+ EncryptUtils .encryptDES (bytesDataDES , bytesKeyDES , "DES/ECB/NoPadding" , null )
306
275
);
307
276
assertEquals (
308
277
resDES ,
309
- EncryptUtils .encryptDES2HexString (
310
- bytesDataDES ,
311
- bytesKeyDES ,
312
- "DES/ECB/NoPadding" ,
313
- null
314
- )
315
- );
316
- assertTrue (
317
- Arrays .equals (
318
- base64Encode (bytesResDES ),
319
- EncryptUtils .encryptDES2Base64 (
320
- bytesDataDES ,
321
- bytesKeyDES ,
322
- "DES/ECB/NoPadding" ,
323
- null
324
- )
325
- )
278
+ EncryptUtils .encryptDES2HexString (bytesDataDES , bytesKeyDES , "DES/ECB/NoPadding" , null )
279
+ );
280
+ assertArrayEquals (
281
+ base64Encode (bytesResDES ),
282
+ EncryptUtils .encryptDES2Base64 (bytesDataDES , bytesKeyDES , "DES/ECB/NoPadding" , null )
326
283
);
327
284
}
328
285
329
286
@ Test
330
287
public void decryptDES () {
331
- assertTrue (
332
- Arrays .equals (
333
- bytesDataDES ,
334
- EncryptUtils .decryptDES (
335
- bytesResDES ,
336
- bytesKeyDES ,
337
- "DES/ECB/NoPadding" ,
338
- null
339
- )
340
- )
341
- );
342
- assertTrue (
343
- Arrays .equals (
344
- bytesDataDES ,
345
- EncryptUtils .decryptHexStringDES (
346
- resDES ,
347
- bytesKeyDES ,
348
- "DES/ECB/NoPadding" ,
349
- null
350
- )
351
- )
352
- );
353
- assertTrue (
354
- Arrays .equals (
355
- bytesDataDES ,
356
- EncryptUtils .decryptBase64DES (
357
- base64Encode (bytesResDES ),
358
- bytesKeyDES ,
359
- "DES/ECB/NoPadding" ,
360
- null
361
- )
362
- )
288
+ assertArrayEquals (
289
+ bytesDataDES ,
290
+ EncryptUtils .decryptDES (bytesResDES , bytesKeyDES , "DES/ECB/NoPadding" , null )
291
+ );
292
+ assertArrayEquals (
293
+ bytesDataDES ,
294
+ EncryptUtils .decryptHexStringDES (resDES , bytesKeyDES , "DES/ECB/NoPadding" , null )
295
+ );
296
+ assertArrayEquals (
297
+ bytesDataDES ,
298
+ EncryptUtils .decryptBase64DES (base64Encode (bytesResDES ), bytesKeyDES , "DES/ECB/NoPadding" , null )
363
299
);
364
300
}
365
301
0 commit comments