1 changed files with 32 additions and 0 deletions
@ -0,0 +1,32 @@ |
|||
package com.ccsens.util; |
|||
|
|||
import cn.hutool.core.codec.Base64; |
|||
import cn.hutool.core.util.CharsetUtil; |
|||
import cn.hutool.crypto.SecureUtil; |
|||
import cn.hutool.crypto.symmetric.SymmetricAlgorithm; |
|||
import cn.hutool.crypto.symmetric.SymmetricCrypto; |
|||
|
|||
/** |
|||
* @author 逗 |
|||
*/ |
|||
public class SymmetricCryptoUtil { |
|||
|
|||
/**生成密钥*/ |
|||
public String generateKey(){ |
|||
byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded(); |
|||
return Base64.encode(key); |
|||
} |
|||
|
|||
/**加密*/ |
|||
public String encrypt(String key, String value){ |
|||
SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, Base64.decode(key)); |
|||
return aes.encryptHex(value); |
|||
} |
|||
|
|||
/**解密*/ |
|||
public String decode(String key, String encryptString){ |
|||
SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, Base64.decode(key)); |
|||
//解密为字符串
|
|||
return aes.decryptStr(encryptString, CharsetUtil.CHARSET_UTF_8); |
|||
} |
|||
} |
Loading…
Reference in new issue