Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

암호화 구현 관련 문서 #23

Open
hyunsb opened this issue Jul 31, 2023 · 0 comments
Open

암호화 구현 관련 문서 #23

hyunsb opened this issue Jul 31, 2023 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@hyunsb
Copy link
Member

hyunsb commented Jul 31, 2023

애플리케이션 서버에서 회원가입 요청 테이블에 데이터를 저장할 때 암호화를 해서 저장할 것이다.
그러면 관리자 측에서는 암호화 할 필요 없이 그냥 회원 테이블에 그대로 저장하면 되는 구조이다.
관리자 기능에서 유저 정보를 뿌려줄 일이 있기 때문에 복호화는 해야한다.

⭐문제점

기존에 유틸 클래스로 관리되던 암호화 관련 클래스는 DTO와 강한 의존성을 가지고 있었다.
따라서 의존성을 최대한 약하게 하려 한다.

⭐해결방법

암호화 클래스는 필수적으로 암호화, 복호화 메서드를 가져야 한다.
그렇기에 두 메서드를 가지는 인터페이스를 생성하여 추상화 한다.

public interface Encrypter {
    public String 암호화();
    public String 복호화();
}

원하는 암호화 알고리즘으로 구현체를 생성하고,
스프링 시큐리티 설정 클래스에서 빈으로 등록한다.

@Bean
public Encrypter encrypter() {
    return new encrypter구현클래스();
}

여기서 문제 발생!

  • 암호화 클래스는 암호화 키를 환경변수에 저장하고 이를 DI 받아서 사용하는 구조이다.
  • 따라서 위의 코드처럼 bean에 직접 등록하여 사용하려면 Configuration 클래스에서 환경변수를 DI 받고 암호화 클래스 생성자를 호출하면서 넘겨줘야한다.

암호화 방식을 여러개 만들어놓고 사용한다고 가정했을 때는 위의 방식이 옳아 보인다.

서비스 레이어에서 암호화 클래스 빈에서 주입 받은 다음에 DTO로 넘겨준다.
DTO에서는 인터페이스를 파라매터로 받아서 복호화 한다.

약한 의존성 결합 굳

@hyunsb hyunsb added the documentation Improvements or additions to documentation label Jul 31, 2023
@hyunsb hyunsb changed the title 암호화 임시 저장 암호화 구현 관련 문서 Jul 31, 2023
@hyunsb hyunsb self-assigned this Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant