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
728x90
반응형
'Study > Spring' 카테고리의 다른 글
구글 로그인 api 웹 인증하기 (0) | 2020.11.02 |
---|---|
Spring UTF-8 한글 깨짐 (0) | 2020.10.26 |
AOP란? (AOP 적용 예제) (0) | 2020.10.16 |
Interceptor (0) | 2020.10.13 |
스프링 Filter 만들기 (0) | 2020.10.13 |
댓글