docker-compose/docker-compose.yml
@@ -38,7 +38,7 @@ # - 7848:7848 - 8848:8848 - 9848:9848 # - 9849:9849 # - 9849:9849 depends_on: - se-mysql networks: se-auth/src/main/java/com/se/auth/controller/HealthController.java
@@ -5,13 +5,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * 健康控制器 * * @author WWW * @date 2024-08-24 */ @RestController @SuppressWarnings("ALL") public class HealthController extends BaseController { @GetMapping("/health") public long test() { se-common/se-common-core/src/main/java/com/se/common/core/utils/AesUtils.java
@@ -4,77 +4,30 @@ import javax.crypto.spec.SecretKeySpec; import java.util.Base64; /** * AES加密工具 * * @author WWW * @date 2024-08-25 */ @SuppressWarnings("ALL") public class AesUtils { /** * 密钥长度必须是16 */ private static final String DEFAULT_KEY = "A#s_zZ3seRve_k.y"; private static final String KEY_ALGORITHM = "AES"; /** * 算法 */ private static final String ALGORITHMSTR = "AES/ECB/PKCS5Padding"; /** * aes解密 * * @param encrypt 内容 * @return * @throws Exception */ public static String decrypt(String encrypt) throws Exception { return decrypt(encrypt, DEFAULT_KEY); } /** * aes加密 * * @param content 内容 * @return * @throws Exception */ public static String encrypt(String content) throws Exception { return encrypt(content, DEFAULT_KEY); } /** * base 64 encode * * @param bytes 待编码的byte[] * @return 编码后的base64 code */ private static String base64Encode(byte[] bytes) { return Base64.getEncoder().encodeToString(bytes); } /** * base 64 decode * * @param base64Code 待解码的base64 code * @return 解码后的byte[] * @throws Exception */ private static byte[] base64Decode(String base64Code) { return StringUtils.isEmpty(base64Code) ? null : Base64.getDecoder().decode(base64Code); } /** * AES加密 * * @param content 待加密的内容 * @param encryptKey 加密密钥 * @return 加密后的byte[] * @throws Exception */ private static byte[] aesEncryptToBytes(String content, String encryptKey) throws Exception { // KeyGenerator kGen = KeyGenerator.getInstance(KEY_ALGORITHM) // kGen.init(128) @@ -85,38 +38,14 @@ return cipher.doFinal(content.getBytes("utf-8")); } /** * AES加密为base 64 code * * @param content 待加密的内容 * @param encryptKey 加密密钥 * @return 加密后的base 64 code * @throws Exception */ public static String encrypt(String content, String encryptKey) throws Exception { return base64Encode(aesEncryptToBytes(content, encryptKey)); } /** * 将base 64 code AES解密 * * @param encryptStr 待解密的base 64 code * @param decryptKey 解密密钥 * @return 解密后的string * @throws Exception */ public static String decrypt(String encryptStr, String decryptKey) throws Exception { return StringUtils.isEmpty(encryptStr) ? null : aesDecryptByBytes(base64Decode(encryptStr), decryptKey); } /** * AES解密 * * @param encryptBytes 待解密的byte[] * @param decryptKey 解密密钥 * @return 解密后的String * @throws Exception */ private static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception { // KeyGenerator kGen = KeyGenerator.getInstance(KEY_ALGORITHM) // kGen.init(128) se-common/se-common-core/src/main/java/com/se/common/core/utils/RsaUtils.java
@@ -16,53 +16,24 @@ import java.util.HashMap; import java.util.Map; /** * RSA工具类 * * @author WWW * @date 2024-08-25 */ @SuppressWarnings("ALL") public class RsaUtils { /** * 私钥 */ private static String privateKey; /** * 公钥 */ private static String publicKey; /** * 密钥算法 */ private static final String KEY_ALGORITHM = "RSA"; /** * RSA密钥长度:1024 或 2048 */ private static final int DEFAULT_RSA_KEY_SIZE = 1024; /** * 日志 */ private static final Logger log = LoggerFactory.getLogger(RsaUtils.class); /** * 生成公私钥 */ public static void generate() { Map<String, String> result = generateRsaKey(DEFAULT_RSA_KEY_SIZE); System.out.println("公钥为:" + result.get("publicKey")); System.out.println("私钥为:" + result.get("privateKey")); } /** * 获取RSA加密私钥 * * @return * @throws IOException */ public static String getPrivateKey() throws IOException { if (privateKey == null) { InputStream inPrivate = new ClassPathResource("config" + File.separator + "rsa_private_key.txt").getInputStream(); @@ -73,12 +44,6 @@ return privateKey; } /** * 获取RSA加密公钥 * * @return * @throws IOException */ public static String getPublicKey() throws IOException { if (publicKey == null) { InputStream inPrivate = new ClassPathResource("config" + File.separator + "rsa_public_key.txt").getInputStream(); @@ -89,13 +54,6 @@ return publicKey; } /** * 读取文本文件 * * @param fileName 文件路径 * @return * @throws IOException */ public static String readFile(String fileName) throws IOException { File file = new File(fileName); BufferedReader br = new BufferedReader(new FileReader(file)); @@ -111,13 +69,6 @@ return result.toString(); } /** * 把inputStream转成String * * @param is * @return * @throws IOException */ private static String inputStream2String(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -132,28 +83,18 @@ return str; } /** * 生成RSA的公私钥 * * @param keySize 1025 或 2048 * @return */ public static Map<String, String> generateRsaKey(int keySize) { Map<String, String> result = new HashMap<>(2); try { KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM); // 初始化密钥对生成器,密钥大小为1024 2048位 keyPairGen.initialize(keySize, new SecureRandom()); // 生成一个密钥对,保存在keyPair中 KeyPair keyPair = keyPairGen.generateKeyPair(); // 得到公钥字符串 String pub = new String(Base64.encodeBase64(keyPair.getPublic().getEncoded())); result.put("publicKey", pub); // 得到私钥字符串 String pri = new String(Base64.encodeBase64(keyPair.getPrivate().getEncoded())); result.put("privateKey", pri); } catch (Exception ex) { @@ -163,22 +104,13 @@ return result; } /** * RSA私钥解密 * * @param str 加密的字符串 * @return 解密字符串 * @throws Exception 加密过程中的异常信息 */ public static String decrypt(String str) throws Exception { // 64位解码加密后的字符串 byte[] inputByte = Base64.decodeBase64(str.getBytes(StandardCharsets.UTF_8)); // Base64编码的私钥 byte[] decoded = Base64.decodeBase64(getPrivateKey()); RSAPrivateKey priKey = (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded)); // RSA解密:RSA/ECB/NoPadding // RSA/ECB/NoPadding Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.DECRYPT_MODE, priKey); @@ -187,20 +119,11 @@ return outStr; } /** * RSA公钥加密 * * @param str 需要加密的字符串 * @return 密文 * @throws Exception 加密过程中的异常信息 */ public static String encrypt(String str) throws Exception { // Base64编码的公钥 byte[] decoded = Base64.decodeBase64(getPublicKey()); RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded)); // RSA加密:RSA/ECB/NoPadding Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.ENCRYPT_MODE, pubKey); se-gateway/src/main/java/com/se/gateway/handler/HealthController.java
@@ -5,13 +5,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * 健康控制器 * * @author WWW * @date 2024-08-24 */ @RestController @SuppressWarnings("ALL") @RequestMapping("/gateway") public class HealthController extends BaseController { @GetMapping("/health") se-modules/se-system/src/main/java/com/se/system/controller/HealthController.java
@@ -4,13 +4,8 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; /** * 健康控制器 * * @author WWW * @date 2024-08-24 */ @RestController @SuppressWarnings("ALL") public class HealthController extends BaseController { @GetMapping("/health") public long test() { se-modules/se-system/src/main/java/com/se/system/service/impl/IsimUserService.java
@@ -6,12 +6,6 @@ import java.util.List; /** * ISIM用户服务 * * @author WWW * @date 2024-08-30 */ @Slf4j @Service @SuppressWarnings("ALL") se-modules/se-system/src/main/java/com/se/system/service/impl/SyncUserService.java
@@ -11,12 +11,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** * 用户同步服务 * * @author WWW * @date 2024-08-30 */ @Slf4j @Service @SuppressWarnings("ALL") @@ -25,7 +19,6 @@ IsimUserService isimUserService; public void insertUser(SysUser user) { // supplyAsync-带返回值,runAsync-无返回值 CompletableFuture.runAsync(() -> { isimUserService.insertUser(user); }); se-modules/se-system/src/main/resources/logback.xml
@@ -58,7 +58,7 @@ </appender> <!-- 系统模块日志级别控制:info,debug --> <logger name="com.se" level="info" /> <logger name="com.se" level="debug" /> <!-- Spring日志级别控制 --> <logger name="org.springframework" level="warn" />