|
|
@@ -190,18 +190,18 @@ public class AESUtils {
|
|
|
try {
|
|
|
// 1. 自动生成AES密钥
|
|
|
String aesKey = getAutoCreateAESKey();
|
|
|
- AppConfig.LOGGER.info("生成的AES密钥 (Base64编码): " + aesKey);
|
|
|
+ AppConfig.LOGGER.info("生成的AES密钥 (Base64编码): {}", aesKey);
|
|
|
|
|
|
String originalContent = "这是一段需要加密的中文文本!Hello World! 12345.";
|
|
|
- AppConfig.LOGGER.info("原始内容: " + originalContent);
|
|
|
+ AppConfig.LOGGER.info("原始内容: {}", originalContent);
|
|
|
|
|
|
// 2. 使用生成的密钥进行加密
|
|
|
String encryptedHex = encrypt2Hex(originalContent, aesKey);
|
|
|
- AppConfig.LOGGER.info("加密后的内容 (Hex): " + encryptedHex);
|
|
|
+ AppConfig.LOGGER.info("加密后的内容 (Hex): {}", encryptedHex);
|
|
|
|
|
|
// 3. 使用相同的密钥进行解密
|
|
|
String decryptedContent = decryptByHex(encryptedHex, aesKey);
|
|
|
- AppConfig.LOGGER.info("解密后的内容: " + decryptedContent);
|
|
|
+ AppConfig.LOGGER.info("解密后的内容: {}", decryptedContent);
|
|
|
|
|
|
// 4. 验证加密解密是否一致
|
|
|
if (originalContent.equals(decryptedContent)) {
|
|
|
@@ -216,15 +216,15 @@ public class AESUtils {
|
|
|
// 这是一个随机生成的16字节密钥的Base64编码,直接硬编码,实际应用中应避免
|
|
|
String fixedKeyBase64 = "yL4k/J11mR82tH+a+3M69g=="; // 这是一个随机生成的16字节密钥的Base64编码
|
|
|
|
|
|
- AppConfig.LOGGER.info("固定密钥 (Base64编码): " + fixedKeyBase64);
|
|
|
+ AppConfig.LOGGER.info("固定密钥 (Base64编码): {}", fixedKeyBase64);
|
|
|
String fixedContent = "测试固定密钥加密解密。";
|
|
|
- AppConfig.LOGGER.info("原始固定内容: " + fixedContent);
|
|
|
+ AppConfig.LOGGER.info("原始固定内容: {}", fixedContent);
|
|
|
|
|
|
String fixedEncryptedHex = encrypt2Hex(fixedContent, fixedKeyBase64);
|
|
|
- AppConfig.LOGGER.info("固定密钥加密后的内容 (Hex): " + fixedEncryptedHex);
|
|
|
+ AppConfig.LOGGER.info("固定密钥加密后的内容 (Hex): {}", fixedEncryptedHex);
|
|
|
|
|
|
String fixedDecryptedContent = decryptByHex(fixedEncryptedHex, fixedKeyBase64);
|
|
|
- AppConfig.LOGGER.info("固定密钥解密后的内容: " + fixedDecryptedContent);
|
|
|
+ AppConfig.LOGGER.info("固定密钥解密后的内容: {}", fixedDecryptedContent);
|
|
|
|
|
|
if (fixedContent.equals(fixedDecryptedContent)) {
|
|
|
AppConfig.LOGGER.info("固定密钥加密解密验证成功!");
|
|
|
@@ -233,10 +233,10 @@ public class AESUtils {
|
|
|
}
|
|
|
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
- AppConfig.LOGGER.error("错误:不支持的加密算法。" + e.getMessage());
|
|
|
+ AppConfig.LOGGER.error("错误:不支持的加密算法。{}", e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
} catch (Exception e) {
|
|
|
- AppConfig.LOGGER.error("加密解密过程中发生错误:" + e.getMessage());
|
|
|
+ AppConfig.LOGGER.error("加密解密过程中发生错误:{}", e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|