1111import java .security .KeyPairGenerator ;
1212import java .security .NoSuchAlgorithmException ;
1313import java .security .SecureRandom ;
14- import java .util .Arrays ;
1514
1615import static com .blankj .utilcode .util .TestConfig .PATH_ENCRYPT ;
1716import static org .junit .Assert .assertArrayEquals ;
1817import static org .junit .Assert .assertEquals ;
19- import static org .junit .Assert .assertTrue ;
2018
2119
2220/**
@@ -82,11 +80,9 @@ public void encryptSHA1() {
8280 blankjSHA1 ,
8381 EncryptUtils .encryptSHA1ToString ("blankj" .getBytes ())
8482 );
85- assertTrue (
86- Arrays .equals (
87- hexString2Bytes (blankjSHA1 ),
88- EncryptUtils .encryptSHA1 ("blankj" .getBytes ())
89- )
83+ assertArrayEquals (
84+ hexString2Bytes (blankjSHA1 ),
85+ EncryptUtils .encryptSHA1 ("blankj" .getBytes ())
9086 );
9187 }
9288
@@ -101,11 +97,9 @@ public void encryptSHA224() {
10197 blankjSHA224 ,
10298 EncryptUtils .encryptSHA224ToString ("blankj" .getBytes ())
10399 );
104- assertTrue (
105- Arrays .equals (
106- hexString2Bytes (blankjSHA224 ),
107- EncryptUtils .encryptSHA224 ("blankj" .getBytes ())
108- )
100+ assertArrayEquals (
101+ hexString2Bytes (blankjSHA224 ),
102+ EncryptUtils .encryptSHA224 ("blankj" .getBytes ())
109103 );
110104 }
111105
@@ -120,12 +114,10 @@ public void encryptSHA256() {
120114 blankjSHA256 ,
121115 EncryptUtils .encryptSHA256ToString ("blankj" .getBytes ())
122116 );
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+
129121 }
130122
131123 @ Test
@@ -139,11 +131,9 @@ public void encryptSHA384() {
139131 blankjSHA384 ,
140132 EncryptUtils .encryptSHA384ToString ("blankj" .getBytes ())
141133 );
142- assertTrue (
143- Arrays .equals (
144- hexString2Bytes (blankjSHA384 ),
145- EncryptUtils .encryptSHA384 ("blankj" .getBytes ())
146- )
134+ assertArrayEquals (
135+ hexString2Bytes (blankjSHA384 ),
136+ EncryptUtils .encryptSHA384 ("blankj" .getBytes ())
147137 );
148138 }
149139
@@ -158,11 +148,9 @@ public void encryptSHA512() {
158148 blankjSHA512 ,
159149 EncryptUtils .encryptSHA512ToString ("blankj" .getBytes ())
160150 );
161- assertTrue (
162- Arrays .equals (
163- hexString2Bytes (blankjSHA512 ),
164- EncryptUtils .encryptSHA512 ("blankj" .getBytes ())
165- )
151+ assertArrayEquals (
152+ hexString2Bytes (blankjSHA512 ),
153+ EncryptUtils .encryptSHA512 ("blankj" .getBytes ())
166154 );
167155 }
168156
@@ -181,11 +169,9 @@ public void encryptHmacMD5() {
181169 blankjHmacMD5 ,
182170 EncryptUtils .encryptHmacMD5ToString ("blankj" .getBytes (), blankjHmackey .getBytes ())
183171 );
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 ())
189175 );
190176 }
191177
@@ -200,11 +186,9 @@ public void encryptHmacSHA1() {
200186 blankjHmacSHA1 ,
201187 EncryptUtils .encryptHmacSHA1ToString ("blankj" .getBytes (), blankjHmackey .getBytes ())
202188 );
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 ())
208192 );
209193 }
210194
@@ -219,11 +203,9 @@ public void encryptHmacSHA224() {
219203 blankjHmacSHA224 ,
220204 EncryptUtils .encryptHmacSHA224ToString ("blankj" .getBytes (), blankjHmackey .getBytes ())
221205 );
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 ())
227209 );
228210 }
229211
@@ -238,11 +220,9 @@ public void encryptHmacSHA256() {
238220 blankjHmacSHA256 ,
239221 EncryptUtils .encryptHmacSHA256ToString ("blankj" .getBytes (), blankjHmackey .getBytes ())
240222 );
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 ())
246226 );
247227 }
248228
@@ -257,11 +237,9 @@ public void encryptHmacSHA384() {
257237 blankjHmacSHA384 ,
258238 EncryptUtils .encryptHmacSHA384ToString ("blankj" .getBytes (), blankjHmackey .getBytes ())
259239 );
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 ())
265243 );
266244 }
267245
@@ -275,11 +253,9 @@ public void encryptHmacSHA512() {
275253 blankjHmacSHA512 ,
276254 EncryptUtils .encryptHmacSHA512ToString ("blankj" .getBytes (), blankjHmackey .getBytes ())
277255 );
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 ())
283259 );
284260 }
285261
@@ -293,73 +269,33 @@ public void encryptHmacSHA512() {
293269
294270 @ Test
295271 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 )
306275 );
307276 assertEquals (
308277 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 )
326283 );
327284 }
328285
329286 @ Test
330287 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 )
363299 );
364300 }
365301
0 commit comments