[ jsp ] 정부프레임워크 (egovframework) crypto 를 통한 해쉬 만들고 적용하는 방법 > jsp&servlet

본문 바로가기

사이트 내 전체검색

jsp&servlet

[ jsp ] 정부프레임워크 (egovframework) crypto 를 통한 해쉬 만들고 적용하는 방법

작성일 22-07-27 13:37

페이지 정보

작성자 웹지기 조회 2,622회 댓글 0건

본문

정부프레임워크 (egovframework)에서 crypto를 통해 해쉬를 만들고 적용하는 방법

 

1) 해쉬 만들기 테스트 파일 작성

/src/test/java 에 새로운 패키지 > egovframework.com.crypto.xmlconfig 생성

/src/test/java/egovframework.com.crypto.xmlconfig/ 에 새로운 클래스 파일 EgovEnvCryptoAlgorithmCresteTest 생성

egovframe.go.kr 로 이동 

개발프레임워크 실행환경 > 프레임워크 실행환경 4.0 > 클릭

개발프레임워크 실행환경 4.0 > 공통기반 > crypto > crypto간소화 > 클릭

crypto 간소화 서비스 

 

Crypto algorithmKey, algorithmKeyHash 생성

Crypto Config 설정에 algorithmKey, algorithmKeyHash 인코딩 키 생성 방법을 제공한다
하단 코드에서 계정암호화키 키 값을 원하는 값으로 설정한다.

importorg.slf4j.Logger;
importorg.slf4j.LoggerFactory;
importorg.egovframe.rte.fdl.cryptography.EgovPasswordEncoder;
publicclass EgovEnvCryptoAlgorithmCreateTest {privatestaticfinal Logger LOGGER = LoggerFactory.getLogger(EgovEnvCryptoAlgorithmCreateTest.class);
	//계정암호화키 키publicString algorithmKey ="(사용자정의 값)";
	//계정암호화 알고리즘(MD5, SHA-1, SHA-256)publicString algorithm ="SHA-256";
	//계정암호화키 블럭사이즈publicint algorithmBlockSize =1024;
	publicstaticvoid main(String[] args){
		EgovEnvCryptoAlgorithmCreateTest cryptoTest =new EgovEnvCryptoAlgorithmCreateTest();
 
		EgovPasswordEncoder egovPasswordEncoder =new EgovPasswordEncoder();
		egovPasswordEncoder.setAlgorithm(cryptoTest.algorithm);
 
		LOGGER.info("------------------------------------------------------");
		LOGGER.info("알고리즘(algorithm) : "+cryptoTest.algorithm);
		LOGGER.info("알고리즘 키(algorithmKey) : "+cryptoTest.algorithmKey);
		LOGGER.info("알고리즘 키 Hash(algorithmKeyHash) : "+egovPasswordEncoder.encryptPassword(cryptoTest.algorithmKey));
		LOGGER.info("알고리즘 블럭사이즈(algorithmBlockSize)  :"+cryptoTest.algorithmBlockSize);
 
	} 

} 

코드를 복사하여 새로 생성한 EgovEnvCryptoAlgorithmCresteTest 클래스 파일에 붙여 넣기하고 저장을 한다.

 

2) 암호화되 코드 넣기 

파일위에서 마우스 우클릭 > Run As > Java Application > 클릭하게 되면 Console 창에 알고림즘. 알고리즘키, 해쉬 블럭사이즈 등이 나오게 된다.

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoAlgorithmCreateTest] ------------------------------------------------------

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoAlgorithmCreateTest] 알고리즘(algorithm) : SHA-256

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoAlgorithmCreateTest] 알고리즘 키(algorithmKey) : egovframe

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoAlgorithmCreateTest] 알고리즘 키 Hash(algorithmKeyHash) : gdyYs/IZqY86VcWhT8emCYfqY1ahw2vtLG+/FzNqtrQ=

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoAlgorithmCreateTest] 알고리즘 블럭사이즈(algorithmBlockSize)  :1024 

이렇게 생성된 값을

/src/main/resources/egovframework/spring/com/context-crypto.xml 파일에 key, hash 등에 맞게 넣어준다.

 

3) 크림토 테스트 파일 작성하기

/src/test/resources 에 패키지 egovframewrok 생성

/src/test/resources/egovframework 에 패키지 생성 com

/src/test/resources/egovframework/com에 에 context-crypto-test.xml 파일 생성  

환경설정 파일(globals.properties) 암호화

 

환경설정 파일(globals.properties)의 데이터베이스 연결 항목(Url, UserName, Password) 인코딩 값 생성

환경설정 파일에서 데이터베이스 연결 항목(Url, UserName, Password) 인코딩 키 생성 방법을 제공한다. 

아래 부분을 복사해서 넣 새로 생성한 context-crypto-test.xml 파일에 넣어준다.

<beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:egov-crypto="http://maven.egovframe.go.kr/schema/egov-crypto"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd		http://maven.egovframe.go.kr/schema/egov-crypto http://maven.egovframe.go.kr/schema/egov-crypto/egov-crypto-4.0.0.xsd">
 
	<beanname="messageSource"class="org.springframework.context.support.ResourceBundleMessageSource"><propertyname="useCodeAsDefaultMessage"><value>true</value></property><propertyname="basenames"><list><value>classpath:/egovframework/egovProps/globals</value></list></property></bean>
 
    <egov-crypto:configid="egovCryptoConfig"initial="false"crypto="true"algorithm="SHA-256"algorithmKey="(사용자정의 값)"algorithmKeyHash="(생성값)"cryptoBlockSize="1024"/>
 
</beans>

 

4)  암호화 생성 파일 작성

/src/test/java/egovframework.com.crypto.xmlconfig 아래에 EgovEnvCryptoUserTest.java 파일 생성

// 데이터베이스 연결 항목(Url, UserName, Password) 인코딩 값 생성 JAVAimportorg.slf4j.Logger;
importorg.slf4j.LoggerFactory;
importorg.springframework.context.ApplicationContext;
importorg.springframework.context.support.ClassPathXmlApplicationContext;
 
importorg.egovframe.rte.fdl.cryptography.EgovEnvCryptoService;
importorg.egovframe.rte.fdl.cryptography.impl.EgovEnvCryptoServiceImpl;
 
publicclass EgovEnvCryptoUserTest {
 
	privatestaticfinal Logger LOGGER = LoggerFactory.getLogger(EgovEnvCryptoUserTest.class);
 
	publicstaticvoid main(String[] args){
 
		String[] arrCryptoString ={"userId",         //데이터베이스 접속 계정 설정"userPassword",   //데이터베이스 접속 패드워드 설정"url",            //데이터베이스 접속 주소 설정"databaseDriver"//데이터베이스 드라이버};
 
 
		LOGGER.info("------------------------------------------------------");		
		ApplicationContext context =new ClassPathXmlApplicationContext(newString[]{"classpath:/context-crypto-test.xml"});
		EgovEnvCryptoService cryptoService = context.getBean(EgovEnvCryptoServiceImpl.class);
		LOGGER.info("------------------------------------------------------");
 
		String label ="";
		try{for(int i=0; i < arrCryptoString.length; i++){if(i==0)label ="사용자 아이디";
				if(i==1)label ="사용자 비밀번호";
				if(i==2)label ="접속 주소";
				if(i==3)label ="데이터 베이스 드라이버";
				LOGGER.info(label+" 원본(orignal):"+ arrCryptoString[i]);
				LOGGER.info(label+" 인코딩(encrypted):"+ cryptoService.encrypt(arrCryptoString[i]));
				LOGGER.info("------------------------------------------------------");
			}}catch(IllegalArgumentException e){
			LOGGER.error("["+e.getClass()+"] IllegalArgumentException : "+ e.getMessage());
		}catch(Exception e){
			LOGGER.error("["+e.getClass()+"] Exception : "+ e.getMessage());
		}
 
	}
  } 

 이렇게 된 부분에서

"userId",         //데이터베이스 접속 계정 설정

"userPassword",   //데이터베이스 접속 패드워드 설정

"url",            //데이터베이스 접속 주소 설정

"databaseDriver"  //데이터베이스 드라이버

이러한 부분들을

"com", "com01", "url", "databaseDriver" 형태로 넣어주고 

EgovEnvCryptoAlgorithmCreateTest.java 파일에서 마우스 우클릭 > Run As > Java Application > 클릭 하게 되면

console 창에 암호화 된 내용을 얻을 수 있다.

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoUserTest] ------------------------------------------------------

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoUserTest] 사용자 아이디 원본(orignal):userId

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoUserTest] 사용자 아이디 인코딩(encrypted):%2Bn5a7BD6CPuNjHSUL9AK8w%3D%3D

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoUserTest] ------------------------------------------------------

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoUserTest] 사용자 비밀번호 원본(orignal):com01

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoUserTest] 사용자 비밀번호 인코딩(encrypted):xz4fmrSdr1vGGl6UtwPLwA%3D%3D

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoUserTest] ------------------------------------------------------

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoUserTest] 접속 주소 원본(orignal):url

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoUserTest] 접속 주소 인코딩(encrypted):BqvAX86xPPqGQEFCB4aaKw%3D%3D

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoUserTest] ------------------------------------------------------

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoUserTest] 데이터 베이스 드라이버 원본(orignal):databaseDriver

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoUserTest] 데이터 베이스 드라이버 인코딩(encrypted):E4GtXk4i9yK0zjbiKDt5%2Fw%3D%3D

INFO [egovframework.com.crypto.xmlconfig.EgovEnvCryptoUserTest] ------------------------------------------------------ 

 이렇게 얻어진 값을 /src/main/resources/egovframework/egovProps/globals.properties 파일에 적용 시킬 수 있다.


추천0

비추천 0

댓글목록

등록된 댓글이 없습니다.

전체 24건 1 페이지

이미지 목록

게시물 검색
Copyright © 즐거운 코딩 생활 ( funyphp ). All rights reserved.
PC 버전으로 보기