Study/Spring
스프링 암호화 기능
오늘만 사는 여자
2020. 10. 22. 16:41
728x90
반응형
Spring 암호화 해보기
1. pom.xml 작성
<!--스프링시큐리티 web 라이브러리-->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.1.0.RELEASE</version>
</dependency>
<!--스프링시큐리티 core 라이브러리-->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.1.0.RELEASE</version>
</dependency>
<!--스프링시큐리티 config 라이브러리-->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.1.0.RELEASE</version>
</dependency>
2. spring-security.xml 작성
src/main/resources/config 경로에 spring-security.xml 파일을 만들고 코드를 추가한다.
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
<beans:bean id="bcryptPasswordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" />
</beans:beans>
3. web.xml 작성
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:config/root-context.xml
classpath:config/spring-security.xml
</param-value>
<!-- <param-value>/WEB-INF/spring/root-context.xml</param-value> -->
</context-param>
추가하여 준다.
4. Controller 작성
상단에 선언
@Autowired
private BCryptPasswordEncoder pwdEncoder;
String aa = "hello";
String aaPwd = pwdEncoder.encode(aa);
String bb = "hello";
String cc="ldy";
if(pwdEncoder.matches(bb, aaPwd)) {
System.out.println("hello");
}
if(pwdEncoder.matches(cc, aaPwd)) {
System.out.println("ldy");
}else {
System.out.println("not matches");
}
Reference : melonpeach.tistory.com/49
23. 스프링 회원가입 만들기 / 암호화 기능 추가
23. 스프링 회원가입 만들기 / 암호화 기능 추가 안녕하세요 MelonPeach입니다. 오늘은 암호화 기능에대해 포스팅하겠습니다. 사용자의 개인정보를 특수문자, 영어 숫자등으로 암호화를 하여 데이
melonpeach.tistory.com
728x90
반응형