# 민감한 정보에 대한 암호화

왜 암호화를 해야 하는지는 따론 찾아보시길 바란다.

그럼 바로 코드로 시작하자.

<https://github.com/ulisesbocchio/jasypt-spring-boot> 라는 오픈소스를 이용하여 설정값들을 암호화 하도록 하자. 요즘 클라우드서버를 많이 사용하지 예를 들으 아마존 클라우드에서 공짜로 제공하는 kms라는 서비스가 있거든 그걸 사용해도 되지만 일단 오늘은 jasypt를 사용해 보도록 하자.

설정

```properties
datasource.password=blake.com
```

테스트 코드 작성

```java
@Slf4j
@SpringBootTest
public class PropertiesTest {

    @Value("${datasource.password:}")
    private String password;

    @Test
    public void test() {
        log.info("datasource.password : {}", password);
    }

}
```

결과!

```
2022-12-21 14:28:45.506  INFO 70405 --- [           main] com.blake.encypt.PropertiesTest   : datasource.password : blake.com
```

띠롱 \~ 아직은 암호화가 안됐음!

일단 library 추가해야지.

```
<dependency>
    <groupId>com.github.ulisesbocchio</groupId>
    <artifactId>jasypt-spring-boot-starter</artifactId>
    <version>3.0.3</version>
</dependency>
```

pom.xml 하단에 plugin 탭에 추가&#x20;

```
<plugin>
    <groupId>com.github.ulisesbocchio</groupId>
    <artifactId>jasypt-maven-plugin</artifactId>
    <version>3.0.3</version>
</plugin>
```

properties 속성 추가

```properties
jasypt.encryptor.password=blakespace
```

DEC() 로 암화할 대상을 감싼다.

```properties
datasource.password=DEC(blakespace.com)
```

jasypt-maven-plugin 이 DEC()의 내용을 일괄처리한다.

```
mvn jasypt:encrypt -Djasypt.encryptor.password=blakespace
```

주의 : -Djasypt.encryptor.password 명령시 properties 내의 설정된 값이랑 일치하게 해야 암호화 실패한다.

실행후 로그는 아래와 같다!

```
datasource.password=ENC(/AL9nJENCYCh9Pfzdf2xLPsqOZ6HwNgQ3AnMybFAMeOM5GphZlOK6PxzozwtCm+Q)

jasypt.encryptor.password=blakespace
```

암화화 되었으니 이제 복호화를 해볼차례다.

```properties
mvn jasypt:decrypt -Djasypt.encryptor.password=blakespace
```

해당명령은 단순 화면에 출력하는 용도일뿐 실제 파일은 수정하지 않는다.

```
datasource.password=DEC(blakespace.com)

jasypt.encryptor.password=blakespace
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blakes-organization.gitbook.io/rainsister/springboot-2.x/undefined-1/undefined-3.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
