12 changed files with 89 additions and 19 deletions
@ -1,4 +1,4 @@ |
|||
spring: |
|||
profiles: |
|||
active: dev |
|||
include: common, util-dev |
|||
active: test |
|||
include: common, util-test |
@ -1,4 +1,4 @@ |
|||
spring: |
|||
profiles: |
|||
active: dev |
|||
include: util-dev,common |
|||
active: test |
|||
include: util-test,common |
@ -0,0 +1,45 @@ |
|||
package com.ccsens.util; |
|||
|
|||
import cn.hutool.core.codec.Base64; |
|||
import cn.hutool.core.lang.Console; |
|||
import cn.hutool.core.util.CharsetUtil; |
|||
import cn.hutool.crypto.SecureUtil; |
|||
import cn.hutool.crypto.symmetric.SymmetricAlgorithm; |
|||
import cn.hutool.crypto.symmetric.SymmetricCrypto; |
|||
import org.junit.Test; |
|||
|
|||
/** |
|||
* @description: |
|||
* @author: wuHuiJuan |
|||
* @create: 2019/12/05 18:05 |
|||
*/ |
|||
public class KeyTest { |
|||
/**生成密钥*/ |
|||
// @Test
|
|||
public void test33(){ |
|||
byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded(); |
|||
Console.log(Base64.encode(key)); |
|||
} |
|||
/**加密*/ |
|||
// @Test
|
|||
public void test3(){ |
|||
String key = "密钥"; |
|||
String string = "数据库密码"; |
|||
SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, Base64.decode(key)); |
|||
String encryptHex = aes.encryptHex(string); |
|||
Console.log("{}",encryptHex); |
|||
} |
|||
|
|||
/**解密*/ |
|||
// @Test
|
|||
public void test4(){ |
|||
//String key = "YmipVlKParz7ehnEv2K4Dw==";
|
|||
String key = System.getenv("CCSENS_TALL_TEST"); |
|||
String encryptString = "68073a279b399baa1fa12cf39bfbb65bfc1480ffee7b659ccc81cf19be8c4473"; |
|||
SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, Base64.decode(key)); |
|||
|
|||
//解密为字符串
|
|||
String decryptStr = aes.decryptStr(encryptString, CharsetUtil.CHARSET_UTF_8); |
|||
Console.log("{}",decryptStr); |
|||
} |
|||
} |
Loading…
Reference in new issue