java
CyptoClient.java中代码
package ***.security.crypto;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.zhengtoon.bjtoon.uia.util.HexUtil;
import org.apache.commons.codec.binary.Base64;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class CyptoClient
{
private static final Logger logger = LogManager.getLogger(CyptoClient.class);
public static final String CHARSET = "UTF-8";
public static String encryptWithAES(String info, String aeskey) {
try {
byte[] key = HexUtil.hexStr2ByteArray(aeskey);
byte[] bytes = info.getBytes();
byte[] encrypt = AES256Coder.encrypt(bytes, key);
return HexUtil.byteArray2HexStr(encrypt);
} catch (Exception e) {
logger.error("encrypt执行失败: " + e.getMessage(), e);
}
return null;
}
public static String decryptWithAES(String info, String aeskey) {
try {
byte[] key = HexUtil.hexStr2ByteArray(aeskey);
byte[] bytes = HexUtil.hexStr2ByteArray(info);
byte[] decrypt = AES256Coder.decrypt(bytes, key);
return new String(decrypt);
} catch (Exception e) {
logger.error("decrypt执行失败: " + e.getMessage(), e);
}
return null;
}
}
HexUtil .java中代码
package ***.security.crypto;
import org.springframework.util.StringUtils;
public class HexUtil {
/**
* 把hex转数组
* @param hexString
* @return
*/
public static byte[] hexStr2ByteArray(String hexString) {
if (StringUtils.isEmpty(hexString))
throw new IllegalArgumentException("this hexString must not b