diff --git a/DDANZI_Server_yml b/DDANZI_Server_yml index e79e997..34f7985 160000 --- a/DDANZI_Server_yml +++ b/DDANZI_Server_yml @@ -1 +1 @@ -Subproject commit e79e997f6652b68b0cd18d1446eea7847a35d97c +Subproject commit 34f7985a8982108cb211225d4421b54616a1325a diff --git a/build.gradle b/build.gradle index 491cb99..4d5d3a5 100644 --- a/build.gradle +++ b/build.gradle @@ -43,6 +43,8 @@ dependencies { // Google Firebase Admin implementation 'com.google.firebase:firebase-admin:9.2.0' testImplementation 'org.springframework.boot:spring-boot-starter-test' + implementation group: 'org.bouncycastle', name: 'bcpkix-jdk15to18', version: '1.78.1' // 최신 버전 확인 후 사용 + } tasks.named('test') { diff --git a/src/main/java/co/orange/ddanzi/service/auth/OAuthService.java b/src/main/java/co/orange/ddanzi/service/auth/OAuthService.java index ae87a1f..0f04e1b 100644 --- a/src/main/java/co/orange/ddanzi/service/auth/OAuthService.java +++ b/src/main/java/co/orange/ddanzi/service/auth/OAuthService.java @@ -18,6 +18,8 @@ import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; +import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; import org.springframework.core.io.ClassPathResource; import org.springframework.http.*; import org.springframework.stereotype.Service; @@ -28,9 +30,8 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.security.KeyFactory; import java.security.PrivateKey; -import java.security.spec.PKCS8EncodedKeySpec; +import java.security.Security; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.*; @@ -180,13 +181,14 @@ private String generateClientSecret() { } private PrivateKey getPrivateKey() { + Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); + JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC"); + try { byte[] privateKeyBytes = Base64.getDecoder().decode(appleProperties.getPrivateKey()); - PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKeyBytes); - KeyFactory keyFactory = KeyFactory.getInstance("EC"); // Elliptic Curve 키 타입 (ES256에 맞게) - - return keyFactory.generatePrivate(keySpec); + PrivateKeyInfo privateKeyInfo = PrivateKeyInfo.getInstance(privateKeyBytes); + return converter.getPrivateKey(privateKeyInfo); } catch (Exception e) { throw new RuntimeException("Error converting private key from String", e); }