2
2
3
3
import org .junit .jupiter .api .BeforeAll ;
4
4
import org .junit .jupiter .api .Test ;
5
- import org .springframework .util .Base64Utils ;
5
+
6
+ import java .util .Base64 ;
6
7
7
8
import static org .junit .jupiter .api .Assertions .assertEquals ;
8
9
@@ -17,19 +18,22 @@ static void before() throws Exception {
17
18
key = aes .getKey ();
18
19
iv = aes .getIv ();
19
20
20
- System .out .println ("keys:" + Base64Utils .encodeToString (key ));
21
- System .out .println ("ivs:" + Base64Utils .encodeToString (iv ));
21
+ Base64 .Encoder encoder = Base64 .getEncoder ();
22
+ System .out .println ("keys:" + encoder .encodeToString (key ));
23
+ System .out .println ("ivs:" + encoder .encodeToString (iv ));
22
24
23
25
}
24
26
25
27
@ Test
26
28
void aes1 () throws Exception {
27
29
AES aes = new AES ();
28
30
String content = "hello world" ;
29
- String encrypt = Base64Utils .encodeToString (aes .encrypt (content .getBytes ()));
31
+ Base64 .Encoder encoder = Base64 .getEncoder ();
32
+ String encrypt = encoder .encodeToString (aes .encrypt (content .getBytes ()));
30
33
System .out .println ("encrypt:" + encrypt );
31
34
32
- String decrypt = new String (aes .decrypt (Base64Utils .decodeFromString (encrypt )));
35
+ Base64 .Decoder decoder = Base64 .getDecoder ();
36
+ String decrypt = new String (aes .decrypt (decoder .decode (encrypt )));
33
37
System .out .println ("decrypt:" + decrypt );
34
38
35
39
assertEquals (content , decrypt , "AES encrypt error" );
@@ -39,7 +43,8 @@ void aes1() throws Exception {
39
43
void aes2 () throws Exception {
40
44
AES aes = new AES (key , iv );
41
45
String content = "hello world" ;
42
- String encrypt = Base64Utils .encodeToString (aes .encrypt (content .getBytes ()));
46
+ Base64 .Encoder encoder = Base64 .getEncoder ();
47
+ String encrypt = encoder .encodeToString (aes .encrypt (content .getBytes ()));
43
48
System .out .println ("encrypt:" + encrypt );
44
49
}
45
50
0 commit comments