From c14737125bb92bc335eb4f21ae0ab96a6de1bc40 Mon Sep 17 00:00:00 2001 From: junhaa <2171326@hansung.ac.kr> Date: Wed, 8 May 2024 02:23:34 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20FEAT.=20webhook=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20=EB=B9=88=20=EC=9D=91=EB=8B=B5=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tbd/domain/faceSwap/util/CryptoUtils.java | 23 ++----------------- .../controller/FaceSwapRestController.java | 5 ++-- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/main/java/fairytale/tbd/domain/faceSwap/util/CryptoUtils.java b/src/main/java/fairytale/tbd/domain/faceSwap/util/CryptoUtils.java index 0163bb7..6b4e0e7 100644 --- a/src/main/java/fairytale/tbd/domain/faceSwap/util/CryptoUtils.java +++ b/src/main/java/fairytale/tbd/domain/faceSwap/util/CryptoUtils.java @@ -6,6 +6,8 @@ import javax.crypto.spec.SecretKeySpec; import java.util.Arrays; import java.nio.charset.StandardCharsets; +import java.util.Base64; + import javax.xml.bind.DatatypeConverter; import org.springframework.beans.factory.annotation.Value; @@ -64,27 +66,6 @@ public static String generateAesDecrypt(String dataEncrypt, String clientId, Str return null; } } - - // Encryption algorithm - public static String generateAesEncrypt(String data, String clientId, String clientSecret) { - try { - byte[] keyBytes = clientSecret.getBytes(StandardCharsets.UTF_8); - byte[] ivBytes = clientId.getBytes(StandardCharsets.UTF_8); - - SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES"); - IvParameterSpec ivSpec = new IvParameterSpec(ivBytes); - - Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); - cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec); - - byte[] encryptedBytes = cipher.doFinal(data.getBytes(StandardCharsets.UTF_8)); - return DatatypeConverter.printHexBinary(encryptedBytes).toLowerCase(); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - // Example usage public String getURL(WebhookRequestDTO.RequestDTO webhookRequestDTO){ String newSignature = generateMsgSignature(clientId, webhookRequestDTO.getTimestamp(), webhookRequestDTO.getNonce(), webhookRequestDTO.getDataEncrypt()); diff --git a/src/main/java/fairytale/tbd/domain/faceSwap/web/controller/FaceSwapRestController.java b/src/main/java/fairytale/tbd/domain/faceSwap/web/controller/FaceSwapRestController.java index 5321864..e4d3c0a 100644 --- a/src/main/java/fairytale/tbd/domain/faceSwap/web/controller/FaceSwapRestController.java +++ b/src/main/java/fairytale/tbd/domain/faceSwap/web/controller/FaceSwapRestController.java @@ -15,6 +15,7 @@ import lombok.RequiredArgsConstructor; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.springframework.http.ResponseEntity; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -80,11 +81,11 @@ public ApiResponse> test(@RequestBody FaceSwapRequestDto.Fac } @PostMapping("/webhook") - public ApiResponse webhook(@RequestBody WebhookRequestDTO.RequestDTO request){ + public ResponseEntity webhook(@RequestBody WebhookRequestDTO.RequestDTO request){ LOGGER.info("request = {}", request); String swapResult = faceSwapApiService.getSwapImageURL(request); LOGGER.info("swapResult = {}", swapResult); - return ApiResponse.onSuccess("thank you"); + return ResponseEntity.ok().build(); } }