Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/main/kotlin/com/yapp2app/common/config/JasyptConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile

/**
* fileName : JasyptConfig
* author : darren
* date : 2025. 12. 24.
* description : Jasypt 암호화 설정
*/
@Profile("!test")
@Configuration
class JasyptConfig(
@Value("\${jasypt.encryptor.password}")
Expand Down
56 changes: 28 additions & 28 deletions src/test/kotlin/com/yapp2app/JasyptTest.kt
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
package com.yapp2app

import org.jasypt.encryption.pbe.PooledPBEStringEncryptor
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig
import org.assertj.core.api.Assertions.assertThat
import org.jasypt.encryption.StringEncryptor
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ActiveProfiles

@ActiveProfiles("test")
class JasyptTest {

private val jasyptStringEncryptor = PooledPBEStringEncryptor().apply {
setConfig(
SimpleStringPBEConfig().apply {
password = "testPasswordForJasypt"
algorithm = "PBEWithHmacSHA512AndAES_256"
setKeyObtentionIterations("1000")
setPoolSize("1")
providerName = "SunJCE"
setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator")
setIvGeneratorClassName("org.jasypt.iv.RandomIvGenerator")
stringOutputType = "base64"
},
)
@SpringBootTest
class JasyptTest(@Autowired private val jasyptStringEncryptor: StringEncryptor) {

@Test
fun jasyptGenerateTest() {
val plain = "test_text"

val encrypted = jasyptStringEncryptor.encrypt(plain)

assertThat(encrypted).doesNotStartWith("ENC(")
assertThat(jasyptStringEncryptor.decrypt(encrypted)).isEqualTo(plain)

println("원본 : $plain")
println("암호화 : ENC($encrypted)")
}

@Test
fun jasyptGeneratTest() {
println("=== Jasypt 암호화 유틸리티 ===")
println()

// 기타 암호화할 값
val text = "test_text"
val encryptedText = jasyptStringEncryptor.encrypt(text)
println(" 원본: $text")
println(" 암호화: ENC($encryptedText)")
println(" 복호화: ${jasyptStringEncryptor.decrypt(encryptedText)}")
println()
fun jasyptDecryptTest() {
val encText = "ENC(Tlk9CbdZwOMF7yO8va+hxDL6DAdNG8szceqMIazx69QgGDRNMkXVBgn8ZiMY2Bec)"

assertThat(encText).startsWith("ENC(")

val encrypted = encText.removePrefix("ENC(").removeSuffix(")")
val decrypted = jasyptStringEncryptor.decrypt(encrypted)

println("암호화 : $encText")
println("복호화 : $decrypted")
}
}
3 changes: 3 additions & 0 deletions src/test/resources/application-jasypt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jasypt:
encryptor:
password: ${JASYPT_PASSWORD}
5 changes: 5 additions & 0 deletions src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ spring:
flyway:
enabled: false


jasypt:
encryptor:
password: ${JASYPT_PASSWORD}

app:
auth:
tokenSecret: testSecretTokenMustBeVeryLongTestSecretDoesNotUseJasypt
Expand Down