티스토리 뷰

728x90

1. 스프링 Security는 hashing(변환) 알고리즘으로 bcrypt을 권장하고 있다. 자세한 건 아래 링크 참조

  1-1 단방향 hasning이다. 즉 암호화 된 값으로 원래값 복원이 불가능하다.

  1-2 추가적인 보호를 위해 hashing 할때 랜덤 값(salt)을 추가하여 사용한다.

 

 

  1-3 BCypt의 장점에 대한 글이다.

 

Why you should use BCrypt to hash passwords

In the online world, passwords play a critical role in keeping your data and other important information safe. For this reason, ensuring…

medium.com

  1-4 Salited Password Hashing에 대한 내용이다.

 

Secure Salted Password Hashing - How to do it Properly

Salted Password Hashing - Doing it Right If you're a web developer, you've probably had to make a user account system. The most important aspect of a user account system is how user passwords are protected. User account databases are hacked frequently, so

crackstation.net

2. BCrypt 사용 방법

  2-1 별도의 웹사이트에서 변환한 값을 저장하는 방법

    2-1-0 Bcrypt hashing값을 구하는 프로그램에서 hash값을 받아서 데이터베이스에 저장한다.

 

Bcrypt Calculator

 

www.bcryptcalculator.com

  2-2 자바 코드로 암호화를 수행하는 방법

  2-3 데이터베이스에 저장할 때 {bcrypt}hashedpassword 형식으로 저장한다. {noop}은 plain text를 사용할 때 지정한다.

 

  2-4 bcrypt는 단방향 hasing이므로 처리된 값만 있으면 된다. 

    2-4-1 로그인 시에 사용자가 입력한 값을 받아서 {op} 를 확인하고 

    2-4-2 사용자가 입력한 plain text을 데이터베이스에 저장된 값에서 salt를 추출하여 hashing한 후

    2-4-3 양 쪽을 비교하여 일치하면 인증이 성공된다.

 

3. 데이터베이스 수정하기

  3-1 password를 저장하는 필드를 68글자로 수정한다. {bcrypt}가 8글자이고 hash된 값의 길이가 60글자 고정이다.

  3-2 아래는 바꾸는 DDL이다.

 

alter table spring_security.users modify column password varchar(68)

 

  3-3 생성한 bcrypt를 가지고 데이터베이스에 저장한다.

    3-3-1 아래는 username이 pilseong이고 password도 pilseong이다.

 

 update users
 set password="{bcrypt}$2a$10$BeFxx1Rh2OlFPPGrOcZVuO801xaUvG45NKppU8F7mgr0/g4GprUEK"
 where username="pilseong"

 

4. 소스코드는 변경 사항이 전혀 없다.

  4-1 데이터베이스 password에 저장된 {bcrypt} 부분을 읽고 어떤 방식으로 검증해야 할지 Spring Security가 판단한다.

 

 

728x90
댓글