BckefuCryptoApplicationTests.java
1.66 KB
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
package com.bckefu.uccc;
import com.bckefu.uccc.aes.AesUtil;
import com.bckefu.uccc.hmac.HmacUtil;
import com.bckefu.uccc.md5.Md5Util;
import com.bckefu.uccc.sha.ShaUtil;
import org.apache.commons.codec.digest.Md5Crypt;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import sun.security.provider.SHA;
import java.io.UnsupportedEncodingException;
import java.security.SignatureException;
@RunWith(SpringRunner.class)
@SpringBootTest
public class BckefuCryptoApplicationTests {
Logger logger = LoggerFactory.getLogger(BckefuCryptoApplication.class);
String data = "caoliang";
// @Test
public void hMacTest() throws SignatureException {
String encrypt = HmacUtil.hmacSha256Hex(data , "key");
System.out.println(encrypt);
}
// @Test
public void shaTest() throws UnsupportedEncodingException {
String encrypt2 = ShaUtil.shaByApache(data);
String encrypt3 = ShaUtil.shaByJDK(data);
logger.info(encrypt2);
logger.info(encrypt3);
}
// @Test
public void md5Test(){
String encrypt2 = Md5Util.encrypt(data);
String encrypt3 = Md5Crypt.md5Crypt(data.getBytes());
logger.info(encrypt2);
logger.info(encrypt3);
}
@Test
public void aesTest(){
String content = "caoliang";
logger.info("加密前:{}" , content);
String encryptResult = AesUtil.encryptAES(content, AesUtil.KEY , AesUtil.IV);
logger.info("加密后 : {}" , encryptResult);
String decryptResult = AesUtil.decryptAES(encryptResult, AesUtil.KEY , AesUtil.IV);
logger.info("解密后:{}" , decryptResult);
}
}