Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- while문
- Spring MVC
- https://www.inflearn.com/course/lecture?courseslug=%ea%b9%80%ec%98%81%ed%95%9c%ec%9d%98-%ec%8b%a4%ec%a0%84-%ec%9e%90%eb%b0%94-%ea%b8%b0%eb%b3%b8%ed%8e%b8&unitid=194709&category=questiondetail&tab=community&q=1314387
- GET방식
- 톰캣
- https://www.inflearn.com/course/lecture?courseslug=%ea%b9%80%ec%98%81%ed%95%9c%ec%9d%98-%ec%8b%a4%ec%a0%84-%ec%9e%90%eb%b0%94-%ea%b8%b0%eb%b3%b8%ed%8e%b8&unitid=194690
- sendRedirect
- CONTINUE
- 김영한
- https://www.inflearn.com/course/lecture?courseslug=%ea%b9%80%ec%98%81%ed%95%9c%ec%9d%98-%ec%8b%a4%ec%a0%84-%ec%9e%90%eb%b0%94-%ea%b8%b0%eb%b3%b8%ed%8e%b8&unitid=194711
- xml
- 다형성 #부모타입 #자식타입
- POST방식
- 요구사항정의서
- JSON형식의 response
- Forwarding
- Request
- Break
- 화면정의서
- webserver #WAS #ServerApp
- Servlet
- 한글깨짐
- 피그마
- 매핑 #
- Dispatcher
- WAS
Archives
- Today
- Total
Step it up now
고객 데이터_비밀번호 암호화하기 본문
aes256 암호화 복호화하는 코드
package com.example.vet.config.aes;
import org.apache.commons.codec.binary.Base64;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.encrypt.BytesEncryptor;
import org.springframework.security.crypto.encrypt.Encryptors;
import org.springframework.security.crypto.keygen.KeyGenerators;
@Configuration
public class AES256Config {
private static final String SECRET_KEY = "@@$@$%AFSFFGCXBBCBB";
private static final String SALT = KeyGenerators.string().generateKey();
public String encrypt(String str) {
BytesEncryptor encryptor = Encryptors.standard(SECRET_KEY, SALT);
byte[] encryptedBytes = encryptor.encrypt(str.getBytes());
return Base64.encodeBase64String(encryptedBytes);
}
public String decrypt(String encryptedString) {
BytesEncryptor decryptor = Encryptors.standard(SECRET_KEY, SALT);
byte[] encryptedBytes = Base64.decodeBase64(encryptedString);
byte[] decryptedBytes = decryptor.decrypt(encryptedBytes);
return new String(decryptedBytes);
}
}
SECRET_KEY
: 암호화 및 복호화에 사용되는 키
반드시 안전한 임의의 값으로 설정해야 한다
또한 SALT는 암호화에 사용되는 추가적인 랜덤 값
이 값은 보안성을 높이기 위해 사용
이 코드는 Spring Security의 Encryptors 클래스를 사용하여 AES256를 구현합니다.
암호화된 문자열은 Base64로 인코딩되어 출력됩니다.
gradle에서 사용시 아래 코드 추가
dependencies {
implementation 'commons-codec:commons-codec:1.15'
}
'프로젝트 > 파이널' 카테고리의 다른 글
controller와 jsp 연결 - 오류 발생 (0) | 2024.02.26 |
---|---|
내 브랜치에서 작업 중에 push 된 부분 pull하기 (0) | 2024.02.22 |
yml파일의 DB설정 (0) | 2024.02.19 |
npm 사용하기.. (0) | 2024.02.18 |
동물병원 그룹웨어_화면정의서(피그마) (1) | 2024.02.05 |