From 7edaa1fb754eb40556de612d17239cd8f03faca9 Mon Sep 17 00:00:00 2001 From: JIWOO Date: Wed, 17 Jul 2024 11:59:31 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9A=B0=20-=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=EC=9E=90=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=EC=97=90=20?= =?UTF-8?q?=EB=B6=84=EC=9F=81=EC=A1=B0=EC=A0=95=20=EC=95=94=ED=98=B8?= =?UTF-8?q?=ED=99=94(MD5)=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/EgovLoginServiceImpl.java | 8 +- src/main/java/seed/utils/SeedCookieUtil.java | 63 + src/main/java/seed/utils/SeedKISA.java | 810 +++++++++++++ src/main/java/seed/utils/SeedUtils.java | 1066 +++++++++++++++++ 4 files changed, 1945 insertions(+), 2 deletions(-) create mode 100644 src/main/java/seed/utils/SeedCookieUtil.java create mode 100644 src/main/java/seed/utils/SeedKISA.java create mode 100644 src/main/java/seed/utils/SeedUtils.java diff --git a/src/main/java/kcc/let/uat/uia/service/impl/EgovLoginServiceImpl.java b/src/main/java/kcc/let/uat/uia/service/impl/EgovLoginServiceImpl.java index f145e518..1e2a7f47 100644 --- a/src/main/java/kcc/let/uat/uia/service/impl/EgovLoginServiceImpl.java +++ b/src/main/java/kcc/let/uat/uia/service/impl/EgovLoginServiceImpl.java @@ -15,6 +15,7 @@ import kcc.let.uat.uia.service.EgovLoginService; import kcc.let.utl.fcc.service.EgovNumberUtil; import kcc.let.utl.fcc.service.EgovStringUtil; import kcc.let.utl.sim.service.EgovFileScrty; +import seed.utils.SeedUtils; /** * 일반 로그인, 인증서 로그인을 처리하는 비즈니스 구현 클래스 @@ -54,9 +55,12 @@ public class EgovLoginServiceImpl extends EgovAbstractServiceImpl implements @Override public LoginVO actionLogin(LoginVO vo) throws Exception { - String enpassword = EgovFileScrty.encryptPassword(vo.getPassword(), vo.getId()); + //String enpassword = EgovFileScrty.encryptPassword(vo.getPassword(), vo.getId()); + + //분쟁조정의 MD5 암호화 사용 + String enpassword = SeedUtils.getSeedMD5Code(vo.getPassword()); + enpassword = SeedUtils.getSeedSHA256Code(enpassword); vo.setPassword(enpassword); - vo.setPassword("72ddc97081262e52953e0a75db05eff2108cfb9b2745083de7fedb65c20e0b85"); // 2. 아이디와 암호화된 비밀번호가 DB와 일치하는지 확인한다. LoginVO loginVO = loginDAO.actionLogin(vo); diff --git a/src/main/java/seed/utils/SeedCookieUtil.java b/src/main/java/seed/utils/SeedCookieUtil.java new file mode 100644 index 00000000..a25ffd56 --- /dev/null +++ b/src/main/java/seed/utils/SeedCookieUtil.java @@ -0,0 +1,63 @@ +package seed.utils; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class SeedCookieUtil { + + /** + * 쿠키를 생성하는 메소드 + * @param HttpServletResponse response response객체 + * @param Integer maxAge 시간설정 60*60*24*365 1년œ + * @param String cookiePath 쿠키가 저장되는 경로 기본 / 입력 + * @param String key 쿠키 key값 + * @param Stirng value 쿠키 value + * */ + public void setCookie(HttpServletResponse response, Integer maxAge, String cookiePath, String key, String value, boolean httpOnly){ + if(httpOnly){ + response.setHeader("Set-Cookie", key+"="+value+"; path=/; HttpOnly"); + } + + Cookie cookie = new Cookie(key, value); + cookie.setMaxAge(maxAge); + cookie.setSecure(true); + cookie.setPath(cookiePath); + response.addCookie(cookie); + } + + /** + * key에 해당하는 쿠키 정보를 가지고 오는 메소드 + * @param HttpServletRequest request 객체 + * @param String key 쿠키 key값 + * @param String 쿠키 정보 + * */ + public String getCookie(HttpServletRequest request, String key){ + Cookie[] cookies = request.getCookies(); + String cookieValue = ""; + if(cookies!=null){ + int iLoop = cookies.length; + for (int i=0; i encByteList = getByteList(encVal, true); + +// System.out.println("복호화할 바이트 시작"); +// for(int i=0; i decByteList = new ArrayList(); + + // IV를 저장하라 변수 선언 + + byte[] byteIV = DEFAULT_IV.getBytes(); + + for(int i=0; i byteList = getByteList(strVal, false); + +// System.out.println("원본 바이트 시작"); +// for(int i=0; i encByteList = new ArrayList(); + + // IV를 저장하라 변수 선언 + byte[] byteIV = DEFAULT_IV.getBytes(); + + for(int i=0; i getByteList(String nomal, boolean isDecode) throws Exception{ + + List byteList = new ArrayList(); + + byte[] tempByte = null; + + if(isDecode){ + BASE64Decoder base64Dec = new BASE64Decoder(); + tempByte = base64Dec.decodeBuffer(nomal); + }else{ + tempByte = nomal.getBytes(CHARACTER_SET); + } + + // seed 암호화를 위해선 byte가 무조건 16byte씩 배열이 생성되어야 함으로 빈배열의 공간수를 계산 + int needBlankLength = 0; + + if(tempByte.length % 16 != 0){ + needBlankLength = 16 - (tempByte.length % 16); + } + + // 위에서 구한 필요한 빈공간의 수를 더하여 다시 배열 생성 + byte[] newTempByte = new byte[tempByte.length + needBlankLength]; + + for(int i=0; i byteList, boolean isEncode) throws Exception{ + + // List에 담긴 byte배열이 16으로 고정임으로 * 16 + byte[] listByte = new byte[byteList.size() * 16]; + + // List에 담긴 byte배열을 하나의 배열(listByte)에 merge + for(int i=0; i0; i--){ + + if(listByte[i - 1] == 0){ + blankCnt++; + }else{ + break; + } + } + + // blank를 제외한 만큼의 데이터만 추출 + byte[] resultByte = new byte[listByte.length - blankCnt]; + + for(int i=0; i>>8)); }; + private static int GetB2(int A){ return (int)(0x000000ff&((A)>>>16)); }; + private static int GetB3(int A){ return (int)(0x000000ff&((A)>>>24)); }; + private static void EndianChange(int dws[]) { dws[0] = (dws[0]>>>24) | (dws[0]<<24) | ((dws[0]<<8)&0x00ff0000)|((dws[0]>>>8)&0x0000ff00); }; + private static int EndianChange(int dws) { return (dws>>>24) | (dws<<24) | ((dws<<8)&0x00ff0000)|((dws>>>8)&0x0000ff00); }; + + /****************************** Seed 암호화를 위한 멤버필드 **********************/ + private static final int pdwRoundKey[] = new int[32]; + // User secret key - mynameisheesungy + private static final byte pbUserKey[] = {(byte)0x6d, (byte)0x79, (byte)0x6e, (byte)0x61, + (byte)0x6d, (byte)0x65, (byte)0x69, (byte)0x73, + (byte)0x68, (byte)0x65, (byte)0x65, (byte)0x73, + (byte)0x75, (byte)0x6e, (byte)0x67, (byte)0x79}; + + // 사용자 입력 문자열 저장 + private static byte pbData[] = new byte[16]; + // input plaintext to be encrypted + private static byte pbCipher[] = new byte[16]; + private static byte pbPlain[] = new byte[16]; + + /***************************** Static 초기화 ************************************/ + static{ + SeedRoundKey(pdwRoundKey, pbUserKey); + } + + /***************************** SEED round function ****************************/ + private static void SeedRound( + int L0[], int L1[], // [in, out] left-side variable at each round + int R0[], int R1[], // [in] right-side variable at each round + int K[]){ // [in] round keys at each round + + int T0, T1; + long T00=0, T11=0; + + // F-function + T0 = R0[0] ^ K[0]; + T1 = R1[0] ^ K[1]; + T1 ^= T0; + T00 = (T0<0) ? (long)(T0 & 0x7fffffff)|(long)(0x80000000) : (long)(T0); + T1 = SS0[GetB0(T1)] ^ SS1[GetB1(T1)] ^ SS2[GetB2(T1)] ^ SS3[GetB3(T1)]; + T11 = (T1<0) ? (long)(T1 & 0x7fffffff)|(long)(0x80000000) : (long)(T1); + T00 += T11; + T0 = SS0[GetB0((int)T00)] ^ SS1[GetB1((int)T00)] ^ SS2[GetB2((int)T00)] ^ SS3[GetB3((int)T00)]; + T00 = (T0<0) ? (long)(T0 & 0x7fffffff)|(long)(0x80000000) : (long)(T0); + T11 += T00; + T1 = SS0[GetB0((int)T11)] ^ SS1[GetB1((int)T11)] ^ SS2[GetB2((int)T11)] ^ SS3[GetB3((int)T11)]; + T11 = (T1<0) ? (long)(T1 & 0x7fffffff)|(long)(0x80000000) : (long)(T1); + T00 += T11; + + //output of F function is added to left-side variable + L0[0] ^= (int)T00; L1[0] ^= (int)T11; + }; + + /************************** SEED encrtyption function *************************/ + private static void SeedEncrypt( + byte pbData[], // [in] data to be encrypted + int pdwRoundKey[], // [in] round keys for encryption + byte outData[]){ // [out] encrypted data + + int L0[] = new int[1]; int L1[] = new int[1]; + int R0[] = new int[1]; int R1[] = new int[1]; + L0[0] = 0x0; L1[0] = 0x0; R0[0] = 0x0; R1[0] = 0x0; + int K[] = new int[2]; + int nCount = 0; + + //Set up input values for encryption + L0[0] = ((int)pbData[0]&0x000000ff); + L0[0] = ((L0[0])<<8)^((int)pbData[1]&0x000000ff); + L0[0] = ((L0[0])<<8)^((int)pbData[2]&0x000000ff); + L0[0] = ((L0[0])<<8)^((int)pbData[3]&0x000000ff); + + L1[0] = ((int)pbData[4]&0x000000ff); + L1[0] = ((L1[0])<<8)^((int)pbData[5]&0x000000ff); + L1[0] = ((L1[0])<<8)^((int)pbData[6]&0x000000ff); + L1[0] = ((L1[0])<<8)^((int)pbData[7]&0x000000ff); + + R0[0] = ((int)pbData[8]&0x000000ff); + R0[0] = ((R0[0])<<8)^((int)pbData[9]&0x000000ff); + R0[0] = ((R0[0])<<8)^((int)pbData[10]&0x000000ff); + R0[0] = ((R0[0])<<8)^((int)pbData[11]&0x000000ff); + + R1[0] = ((int)pbData[12]&0x000000ff); + R1[0] = ((R1[0])<<8)^((int)pbData[13]&0x000000ff); + R1[0] = ((R1[0])<<8)^((int)pbData[14]&0x000000ff); + R1[0] = ((R1[0])<<8)^((int)pbData[15]&0x000000ff); + + //Reorder for little endian + //Because java virtual machine use big endian order in default + if (!ENDIAN) {EndianChange(L0); EndianChange(L1); EndianChange(R0); EndianChange(R1);}; + + K[0] = pdwRoundKey[nCount++]; K[1] = pdwRoundKey[nCount++]; + SeedRound(L0, L1, R0, R1, K); /* 1 */ + K[0] = pdwRoundKey[nCount++]; K[1] = pdwRoundKey[nCount++]; + SeedRound(R0, R1, L0, L1, K); /* 2 */ + K[0] = pdwRoundKey[nCount++]; K[1] = pdwRoundKey[nCount++]; + SeedRound(L0, L1, R0, R1, K); /* 3 */ + K[0] = pdwRoundKey[nCount++]; K[1] = pdwRoundKey[nCount++]; + SeedRound(R0, R1, L0, L1, K); /* 4 */ + K[0] = pdwRoundKey[nCount++]; K[1] = pdwRoundKey[nCount++]; + SeedRound(L0, L1, R0, R1, K); /* 5 */ + K[0] = pdwRoundKey[nCount++]; K[1] = pdwRoundKey[nCount++]; + SeedRound(R0, R1, L0, L1, K); /* 6 */ + K[0] = pdwRoundKey[nCount++]; K[1] = pdwRoundKey[nCount++]; + SeedRound(L0, L1, R0, R1, K); /* 7 */ + K[0] = pdwRoundKey[nCount++]; K[1] = pdwRoundKey[nCount++]; + SeedRound(R0, R1, L0, L1, K); /* 8 */ + K[0] = pdwRoundKey[nCount++]; K[1] = pdwRoundKey[nCount++]; + SeedRound(L0, L1, R0, R1, K); /* 9 */ + K[0] = pdwRoundKey[nCount++]; K[1] = pdwRoundKey[nCount++]; + SeedRound(R0, R1, L0, L1, K); /* 10 */ + K[0] = pdwRoundKey[nCount++]; K[1] = pdwRoundKey[nCount++]; + SeedRound(L0, L1, R0, R1, K); /* 11 */ + K[0] = pdwRoundKey[nCount++]; K[1] = pdwRoundKey[nCount++]; + SeedRound(R0, R1, L0, L1, K); /* 12 */ + K[0] = pdwRoundKey[nCount++]; K[1] = pdwRoundKey[nCount++]; + SeedRound(L0, L1, R0, R1, K); /* 13 */ + K[0] = pdwRoundKey[nCount++]; K[1] = pdwRoundKey[nCount++]; + SeedRound(R0, R1, L0, L1, K); /* 14 */ + K[0] = pdwRoundKey[nCount++]; K[1] = pdwRoundKey[nCount++]; + SeedRound(L0, L1, R0, R1, K); /* 15 */ + K[0] = pdwRoundKey[nCount++]; K[1] = pdwRoundKey[nCount++]; + SeedRound(R0, R1, L0, L1, K); /* 16 */ + + if (!ENDIAN) {EndianChange(L0); EndianChange(L1); EndianChange(R0); EndianChange(R1);}; + + //Copying output values from last round to outData + for (int i=0; i<4; i++){ + outData[i ] = (byte)(((R0[0])>>>(8*(3-i)))&0xff); + outData[4+i ] = (byte)(((R1[0])>>>(8*(3-i)))&0xff); + outData[8+i ] = (byte)(((L0[0])>>>(8*(3-i)))&0xff); + outData[12+i] = (byte)(((L1[0])>>>(8*(3-i)))&0xff); + } + } + + /************************** SEED decrtyption function *************************/ + // Same as encrypt, except that round keys are applied in reverse order + private static void SeedDecrypt( + byte pbData[], // [in] encrypted data + int pdwRoundKey[], // [in] round keys for decryption + byte outData[]){ // [out] data to be encrypted + + int L0[] = new int[1]; int L1[] = new int[1]; + int R0[] = new int[1]; int R1[] = new int[1]; + int K[] = new int[2]; + L0[0] = 0x0; L1[0] = 0x0; R0[0] = 0x0; R1[0] = 0x0; + int nCount = 31; + + // Set up input values for decryption + L0[0] = ((int)pbData[0]&0x000000ff); + L0[0] = ((L0[0])<<8)^((int)pbData[1]&0x000000ff); + L0[0] = ((L0[0])<<8)^((int)pbData[2]&0x000000ff); + L0[0] = ((L0[0])<<8)^((int)pbData[3]&0x000000ff); + + L1[0] = ((int)pbData[4]&0x000000ff); + L1[0] = ((L1[0])<<8)^((int)pbData[5]&0x000000ff); + L1[0] = ((L1[0])<<8)^((int)pbData[6]&0x000000ff); + L1[0] = ((L1[0])<<8)^((int)pbData[7]&0x000000ff); + + R0[0] = ((int)pbData[8]&0x000000ff); + R0[0] = ((R0[0])<<8)^((int)pbData[9]&0x000000ff); + R0[0] = ((R0[0])<<8)^((int)pbData[10]&0x000000ff); + R0[0] = ((R0[0])<<8)^((int)pbData[11]&0x000000ff); + + R1[0] = ((int)pbData[12]&0x000000ff); + R1[0] = ((R1[0])<<8)^((int)pbData[13]&0x000000ff); + R1[0] = ((R1[0])<<8)^((int)pbData[14]&0x000000ff); + R1[0] = ((R1[0])<<8)^((int)pbData[15]&0x000000ff); + + // Reorder for little endian + if (!ENDIAN) {EndianChange(L0); EndianChange(L1); EndianChange(R0); EndianChange(R1);}; + + K[1] = pdwRoundKey[nCount--]; K[0] = pdwRoundKey[nCount--]; + SeedRound(L0, L1, R0, R1, K); /* 1 */ + K[1] = pdwRoundKey[nCount--]; K[0] = pdwRoundKey[nCount--]; + SeedRound(R0, R1, L0, L1, K); /* 2 */ + K[1] = pdwRoundKey[nCount--]; K[0] = pdwRoundKey[nCount--]; + SeedRound(L0, L1, R0, R1, K); /* 3 */ + K[1] = pdwRoundKey[nCount--]; K[0] = pdwRoundKey[nCount--]; + SeedRound(R0, R1, L0, L1, K); /* 4 */ + K[1] = pdwRoundKey[nCount--]; K[0] = pdwRoundKey[nCount--]; + SeedRound(L0, L1, R0, R1, K); /* 5 */ + K[1] = pdwRoundKey[nCount--]; K[0] = pdwRoundKey[nCount--]; + SeedRound(R0, R1, L0, L1, K); /* 6 */ + K[1] = pdwRoundKey[nCount--]; K[0] = pdwRoundKey[nCount--]; + SeedRound(L0, L1, R0, R1, K); /* 7 */ + K[1] = pdwRoundKey[nCount--]; K[0] = pdwRoundKey[nCount--]; + SeedRound(R0, R1, L0, L1, K); /* 8 */ + K[1] = pdwRoundKey[nCount--]; K[0] = pdwRoundKey[nCount--]; + SeedRound(L0, L1, R0, R1, K); /* 9 */ + K[1] = pdwRoundKey[nCount--]; K[0] = pdwRoundKey[nCount--]; + SeedRound(R0, R1, L0, L1, K); /* 10 */ + K[1] = pdwRoundKey[nCount--]; K[0] = pdwRoundKey[nCount--]; + SeedRound(L0, L1, R0, R1, K); /* 11 */ + K[1] = pdwRoundKey[nCount--]; K[0] = pdwRoundKey[nCount--]; + SeedRound(R0, R1, L0, L1, K); /* 12 */ + K[1] = pdwRoundKey[nCount--]; K[0] = pdwRoundKey[nCount--]; + SeedRound(L0, L1, R0, R1, K); /* 13 */ + K[1] = pdwRoundKey[nCount--]; K[0] = pdwRoundKey[nCount--]; + SeedRound(R0, R1, L0, L1, K); /* 14 */ + K[1] = pdwRoundKey[nCount--]; K[0] = pdwRoundKey[nCount--]; + SeedRound(L0, L1, R0, R1, K); /* 15 */ + K[1] = pdwRoundKey[nCount--]; K[0] = pdwRoundKey[nCount]; + SeedRound(R0, R1, L0, L1, K); /* 16 */ + + if (!ENDIAN) {EndianChange(L0); EndianChange(L1); EndianChange(R0); EndianChange(R1);}; + + // Copy output values from last round to outData + for (int i=0; i<4; i++) + { + outData[i ] = (byte)(((R0[0])>>>(8*(3-i)))&0xff); + outData[4+i ] = (byte)(((R1[0])>>>(8*(3-i)))&0xff); + outData[8+i ] = (byte)(((L0[0])>>>(8*(3-i)))&0xff); + outData[12+i] = (byte)(((L1[0])>>>(8*(3-i)))&0xff); + } + } + + /************************ Functions for Key schedule **************************/ + private static void EncRoundKeyUpdate0(int K[], int A[], int B[], int C[], int D[], int Z){ + //int T0, T1; + int T0; + int T00, T11; + T0 = A[0]; + A[0] = (A[0]>>>8) ^ (B[0]<<24); + B[0] = (B[0]>>>8) ^ (T0<<24); + T00 = (int)A[0] + (int)C[0] - (int)KC[Z]; + T11 = (int)B[0] + (int)KC[Z] - (int)D[0]; + K[0] = SS0[GetB0((int)T00)] ^ SS1[GetB1((int)T00)] ^ SS2[GetB2((int)T00)] ^ SS3[GetB3((int)T00)]; + K[1] = SS0[GetB0((int)T11)] ^ SS1[GetB1((int)T11)] ^ SS2[GetB2((int)T11)] ^ SS3[GetB3((int)T11)]; + } + + private static void EncRoundKeyUpdate1(int K[], int A[], int B[], int C[], int D[], int Z){ + //int T0, T1; + int T0; + int T00, T11; + T0 = C[0]; + C[0] = (C[0]<<8) ^ (D[0]>>>24); + D[0] = (D[0]<<8) ^ (T0>>>24); + T00 = (int)A[0] + (int)C[0] - (int)KC[Z]; + T11 = (int)B[0] + (int)KC[Z] - (int)D[0]; + K[0] = SS0[GetB0((int)T00)] ^ SS1[GetB1((int)T00)] ^ SS2[GetB2((int)T00)] ^ SS3[GetB3((int)T00)]; + K[1] = SS0[GetB0((int)T11)] ^ SS1[GetB1((int)T11)] ^ SS2[GetB2((int)T11)] ^ SS3[GetB3((int)T11)]; + } + + /******************************** Key Schedule ********************************/ + private static void SeedRoundKey( + int pdwRoundKey[], // [out] round keys for encryption or decryption + byte pbUserKey[]){ // [in] secret user key + + int A[] = new int[1]; + int B[] = new int[1]; + int C[] = new int[1]; + int D[] = new int[1]; + int K[] = new int[2]; + int T0, T1; + int nCount = 2; + + // Set up input values for Key Schedule + A[0] = ((int)pbUserKey[0]&0x000000ff); + A[0] = (A[0]<<8)^((int)pbUserKey[1]&0x000000ff); + A[0] = (A[0]<<8)^((int)pbUserKey[2]&0x000000ff); + A[0] = (A[0]<<8)^((int)pbUserKey[3]&0x000000ff); + + B[0] = ((int)pbUserKey[4]&0x000000ff); + B[0] = (B[0]<<8)^((int)pbUserKey[5]&0x000000ff); + B[0] = (B[0]<<8)^((int)pbUserKey[6]&0x000000ff); + B[0] = (B[0]<<8)^((int)pbUserKey[7]&0x000000ff); + + C[0] = ((int)pbUserKey[8]&0x000000ff); + C[0] = (C[0]<<8)^((int)pbUserKey[9]&0x000000ff); + C[0] = (C[0]<<8)^((int)pbUserKey[10]&0x000000ff); + C[0] = (C[0]<<8)^((int)pbUserKey[11]&0x000000ff); + + D[0] = ((int)pbUserKey[12]&0x000000ff); + D[0] = (D[0]<<8)^((int)pbUserKey[13]&0x000000ff); + D[0] = (D[0]<<8)^((int)pbUserKey[14]&0x000000ff); + D[0] = (D[0]<<8)^((int)pbUserKey[15]&0x000000ff); + + // reorder for little endian + if (!ENDIAN) {A[0]=EndianChange(A[0]); B[0]=EndianChange(B[0]); C[0]=EndianChange(C[0]); D[0]=EndianChange(D[0]);}; + + T0 = (int)A[0] + (int)C[0] - (int)KC[0]; + T1 = (int)B[0] - (int)D[0] + (int)KC[0]; + + pdwRoundKey[0] = SS0[GetB0((int)T0)] ^ SS1[GetB1((int)T0)] ^ SS2[GetB2((int)T0)] ^ SS3[GetB3((int)T0)]; + pdwRoundKey[1] = SS0[GetB0((int)T1)] ^ SS1[GetB1((int)T1)] ^ SS2[GetB2((int)T1)] ^ SS3[GetB3((int)T1)]; + + EncRoundKeyUpdate0(K, A, B, C, D, 1 ); + pdwRoundKey[nCount++] = K[0]; pdwRoundKey[nCount++] = K[1]; + + EncRoundKeyUpdate1(K, A, B, C, D, 2 ); + pdwRoundKey[nCount++] = K[0]; pdwRoundKey[nCount++] = K[1]; + + EncRoundKeyUpdate0(K, A, B, C, D, 3 ); + pdwRoundKey[nCount++] = K[0]; pdwRoundKey[nCount++] = K[1]; + + EncRoundKeyUpdate1(K, A, B, C, D, 4 ); + pdwRoundKey[nCount++] = K[0]; pdwRoundKey[nCount++] = K[1]; + + EncRoundKeyUpdate0(K, A, B, C, D, 5 ); + pdwRoundKey[nCount++] = K[0]; pdwRoundKey[nCount++] = K[1]; + + EncRoundKeyUpdate1(K, A, B, C, D, 6 ); + pdwRoundKey[nCount++] = K[0]; pdwRoundKey[nCount++] = K[1]; + + EncRoundKeyUpdate0(K, A, B, C, D, 7 ); + pdwRoundKey[nCount++] = K[0]; pdwRoundKey[nCount++] = K[1]; + + EncRoundKeyUpdate1(K, A, B, C, D, 8 ); + pdwRoundKey[nCount++] = K[0]; pdwRoundKey[nCount++] = K[1]; + + EncRoundKeyUpdate0(K, A, B, C, D, 9 ); + pdwRoundKey[nCount++] = K[0]; pdwRoundKey[nCount++] = K[1]; + + EncRoundKeyUpdate1(K, A, B, C, D, 10); + pdwRoundKey[nCount++] = K[0]; pdwRoundKey[nCount++] = K[1]; + + EncRoundKeyUpdate0(K, A, B, C, D, 11); + pdwRoundKey[nCount++] = K[0]; pdwRoundKey[nCount++] = K[1]; + + EncRoundKeyUpdate1(K, A, B, C, D, 12); + pdwRoundKey[nCount++] = K[0]; pdwRoundKey[nCount++] = K[1]; + + EncRoundKeyUpdate0(K, A, B, C, D, 13); + pdwRoundKey[nCount++] = K[0]; pdwRoundKey[nCount++] = K[1]; + + EncRoundKeyUpdate1(K, A, B, C, D, 14); + pdwRoundKey[nCount++] = K[0]; pdwRoundKey[nCount++] = K[1]; + + EncRoundKeyUpdate0(K, A, B, C, D, 15); + pdwRoundKey[nCount++] = K[0]; pdwRoundKey[nCount++] = K[1]; + } + + /****************************** 사용자 정의 함수 *******************************/ + // 암호화 함수 + public static String getPbCipher(String str){ + padding(str); // 16 자가 되지 않으면 (byte)0x00 으로 채워준다. + + SeedEncrypt(pbData, pdwRoundKey, pbCipher); + + return toString(pbCipher); + } + + // 복호화 함수 + public static String getPbPlain(String str){ + pbCipher = toByte(str); // String을 byte[]로 변환 + + SeedDecrypt(pbCipher, pdwRoundKey, pbPlain); + + return toString(pbPlain); + } + + /************** 형변환 함수! + * ( byte 값에 음수 값이 있어서 str.getBytes(), byte.toString()이 + * 제데로 동작하지 않아서 만들어 준 함수 ) + * ***************/ + // Byte[]을 받아서 String 을 리턴한다. + public static String toString(byte[] b){ + StringBuffer sb = new StringBuffer(); + for(int i=0; i pbData.length){ + pbData = null; + return; + } + + for(int i=0; i 생성후 해당 폴더에 대한 권한 설정을 실행 + * 생성된 폴더 및 파일 객체를 위의 메소드로 권한 수정 작업 진행 + * 요거 하면 계정에 따라서 권한이 없어서 문제 발생 될수 있음 + * Was=서버파일관리 권한이 완전 동일 해야함 + * @param String dirPath 폴더 경로 + */ + public static void setSeedMkDirs(String dirPath){ + + File file = new File(dirPath); + + if (file.exists() || file.isDirectory()){ + return; + } + + if(!file.exists()){ + file.mkdirs(); + } + } + + public static void setSeedFileCopy(String inFileName, String outFileName){ + + FileInputStream fis = null; + FileOutputStream fos = null; + + try{ + + fis = new FileInputStream(inFileName); + fos = new FileOutputStream(outFileName); + + byte[] buffer = new byte[(int)1024]; + + int i = 0; + + if (fis != null && fos != null) { + while ((i = fis.read(buffer)) != -1) { + fos.write(buffer, 0, i); + } + } + + fis.close(); + fos.close(); + + }catch (FileNotFoundException e){ + log.error(e); + }catch (IOException e){ + log.error(e); + }catch (Exception e){ + log.error(e); + }finally{ + if(fis!=null){try{fis.close();}catch(IOException e){log.error("CHECK ERROR:",e);}} + if(fos!=null){try{fos.close();}catch(IOException e){log.error("CHECK ERROR:",e);}} + } + } + + public static void setSeedMoveFile(String dirPath, String destPath){ + + File orgFile = new File(dirPath); + File destFile = new File(destPath); + + if(orgFile != null && orgFile.exists()){ + orgFile.renameTo(destFile); + } + } + + public synchronized static void setSeedDeleteFile(String dirPath){ + + File file = new File(dirPath); + + if(file != null && file.exists()){ + file.delete(); + } + } + + public synchronized static void setSeedDeleteFiles(String dirPath, String noFoloder) { + + File file = new File(dirPath); + + if (!file.exists() || !file.isDirectory()){ + return; + } + + String[] fnameList = file.list(); + + if(fnameList != null && fnameList.length > 0){ + + int fCnt = fnameList.length; + String childPath = ""; + + for(int i = 0; i < fCnt; i++) { + childPath = dirPath+"/"+fnameList[i]; + File f = new File(childPath); + + if(noFoloder != null && !noFoloder.equals("")){ + if(f.getName().equals(noFoloder)){ + continue; + } + } + + if(f != null && !f.isDirectory()) { + f.delete(); //파일이면 바로 삭제 + }else { + setSeedDeleteFiles(childPath, noFoloder); + } + } + } + + File f = new File(dirPath); + f.delete(); + } + + public static void setSeedCopyFiles(File sourcelocation , File targetdirectory, String[] noCopyFolders, String[] noCopyFiles) { + + //디렉토리인 경우 + if (sourcelocation.isDirectory()) { + + boolean chkNoFolder = false; + + for(int i=0; i -1){ + chkNoFolder = true; + break; + } + } + + if(!chkNoFolder){ + //복사될 Directory가 없으면 만듭니다. + if (!targetdirectory.exists()) { + targetdirectory.mkdir(); + } + + String[] children = sourcelocation.list(); + + if(children != null && children.length > 0){ + + for (int i=0; i 0){ + + for(int i=0; i -1){ + chkNoFile = true; + break; + } + } + } + + if(!chkNoFile){ + + //파일인 경우 + InputStream in = null; + OutputStream out = null; + + try{ + + in = new FileInputStream(sourcelocation); + out = new FileOutputStream(targetdirectory); + + //Copy the bits from instream to outstream + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + + in.close(); + out.close(); + + }catch (IOException e){ + log.error("IOException Error"); + }finally{ + if (in != null) { + try{ + in.close(); + }catch (IOException e){ + log.error("IOException Error"); + } + } + + if (out != null) { + try{ + out.close(); + }catch (IOException e){ + log.error("IOException Error"); + } + } + } + } + } + } + + public static ArrayList> getSeedDirFiles(String dirPath, String dirType) { + + ArrayList> arrayList = new ArrayList>(); + + File file = new File(dirPath); + + if (!file.exists() || !file.isDirectory()){ + return null; + } + + String[] fnameList = file.list(); + int fCnt = 0; + if(fnameList != null && fnameList.length > 0){ + fCnt = fnameList.length; + } + String childPath = ""; + + for(int i = 0; i < fCnt; i++) { + childPath = dirPath+"/"+fnameList[i]; + File f = new File(childPath); + + if(f != null){ + + Map dirMap = new HashMap(); + + if(dirType.equals("D") && f.isDirectory()){ + dirMap.put("dirName", f.getName()); + arrayList.add(dirMap); + }else if(dirType.equals("F") && !f.isDirectory()){ + dirMap.put("fileName", f.getName()); + dirMap.put("fileSize", f.length()); + dirMap.put("fileSubType", f.getName().substring(f.getName().lastIndexOf(".")+1)); + arrayList.add(dirMap); + } + } + } + + return arrayList; + } + + public static String getStandardPBEStringDecrypt(String strEncrypt){ + + String strDecrypt = strEncrypt.substring(4, strEncrypt.length()-1); + + StandardPBEStringEncryptor pbeEnc = new StandardPBEStringEncryptor(); + pbeEnc.setPassword("web"); // PBE 값(XML PASSWORD설정) + + return pbeEnc.decrypt(strDecrypt); + } + + public static String setReplaceNull(Object strOriginal){ + + if(strOriginal == null || strOriginal.equals("")){ + strOriginal = ""; + } + +// //주민번호 형태 인 경우 해당 *로 치환 +// strOriginal = strOriginal.toString().replaceAll("\\d{6}(|\\p{Z}|\\p{Z}\\p{Z})\\-(|\\p{Z}|\\p{Z}\\p{Z})[1-4]\\d{6}", "******-*******"); +// strOriginal = strOriginal.toString().replaceAll("\\d{6}(|\\p{Z}|\\p{Z}\\p{Z})\\~(|\\p{Z}|\\p{Z}\\p{Z})[1-4]\\d{6}", "******~*******"); +// +// //휴대폰 번호 인 경우 해당 *로 치환 +// strOriginal = strOriginal.toString().replaceAll("^01(?:0|1|[6-9])(|\\p{Z}|\\p{Z}\\p{Z})-(|\\p{Z}|\\p{Z}\\p{Z})(?:\\d{3}|\\d{4}) - \\d{4}$", "***-****-****"); +// strOriginal = strOriginal.toString().replaceAll("^01(?:0|1|[6-9])(|\\p{Z}|\\p{Z}\\p{Z})~(|\\p{Z}|\\p{Z}\\p{Z})(?:\\d{3}|\\d{4}) ~ \\d{4}$", "***~****~****"); +// +// //일반전화 번호, 팩스 번호 인 경우 해당 *로 치환 +// strOriginal = strOriginal.toString().replaceAll("^\\d{2,3}(|\\p{Z}|\\p{Z}\\p{Z})-(|\\p{Z}|\\p{Z}\\p{Z})\\d{3,4}(|\\p{Z}|\\p{Z}\\p{Z})-(|\\p{Z}|\\p{Z}\\p{Z})\\d{4}$", "***-****-****"); +// strOriginal = strOriginal.toString().replaceAll("^\\d{2,3}(|\\p{Z}|\\p{Z}\\p{Z})~(|\\p{Z}|\\p{Z}\\p{Z})\\d{3,4}(|\\p{Z}|\\p{Z}\\p{Z})~(|\\p{Z}|\\p{Z}\\p{Z})\\d{4}$", "***~****~****"); +// +// //카드번호 인 경우 해당 *로 치환 +// strOriginal = strOriginal.toString().replaceAll("\\d{4}(|\\p{Z}|\\p{Z}\\p{Z})-(|\\p{Z}|\\p{Z}\\p{Z})\\d{4}(|\\p{Z}|\\p{Z}\\p{Z})-(|\\p{Z}|\\p{Z}\\p{Z})\\d{4}(|\\p{Z}|\\p{Z}\\p{Z})-(|\\p{Z}|\\p{Z}\\p{Z})\\d{4}", "****-****-****-****"); +// strOriginal = strOriginal.toString().replaceAll("\\d{4}(|\\p{Z}|\\p{Z}\\p{Z})~(|\\p{Z}|\\p{Z}\\p{Z})\\d{4}(|\\p{Z}|\\p{Z}\\p{Z})~(|\\p{Z}|\\p{Z}\\p{Z})\\d{4}(|\\p{Z}|\\p{Z}\\p{Z})~(|\\p{Z}|\\p{Z}\\p{Z})\\d{4}", "****~****~****~****"); + + return strOriginal.toString(); + } + + public static String setReplaceNull(Object strOriginal, Object strReplace){ + + if(strOriginal == null || strOriginal.equals("") || strOriginal.equals("null")){ + return strReplace.toString(); + } + + return strOriginal.toString(); + } + + public static void getZipFile(String path, String fileName) { + + File f = new File(path); //파일이름미포함 + String files[] = f.list(); // f object 에 있는 파일목록 + + String outFilename = path + "/" + fileName + ".zip"; + int number = 1; + + while (true) { + File newFile = new File(outFilename); + if (newFile != null && newFile.exists()) { + outFilename = path + "/" + fileName + "_" + number + ".txt"; + number++; + } else { + break; + } + } + + int size = 1024; + //Create a buffer for reading the files + byte[] buf = new byte[size]; + + //Create the ZIP file + ZipOutputStream zos = null; + FileInputStream fis = null; + + try{ + + zos = new ZipOutputStream(new FileOutputStream(outFilename)); + + //Compress the files + if(files != null && files.length > 0){ + + for (int i = 0; i < files.length; i++) { + fis = new FileInputStream(path + "/" + files[i]); + + //Add ZIP entry to output stream. + zos.putNextEntry(new ZipEntry(files[i])); // Zip 파일에 경로를 정하여 저장할수 있다. + //Transfer bytes from the file to the ZIP file + + int len; + while ((len = fis.read(buf, 0, size)) > 0) { + zos.write(buf, 0, len); + } + + //Complete the entry + zos.closeEntry(); + fis.close(); + } + } + + //Complete the ZIP file + zos.close(); + }catch (FileNotFoundException e){ + log.error("FileNotFoundException Error"); + }catch (IOException e){ + log.error("IOException Error"); + }finally{ + if (fis != null) { + try{ + fis.close(); + }catch (IOException e){ + log.error("IOException Error"); + } + } + + if (zos != null) { + try{ + zos.close(); + }catch (IOException e){ + log.error("IOException Error"); + } + } + } + } + + public static void setUnZipFile(String zipPath, String unzipPath) { + + File zipFile = new File(zipPath); //파일이름포함 + File targetDir = new File(unzipPath); //미포함 + + FileInputStream fis = null; + ZipInputStream zis = null; + FileOutputStream fos = null; + + try{ + + fis = new FileInputStream(zipFile); + zis = new ZipInputStream(fis); // ZipInputStream + + ZipEntry zentry = null; + + while ((zentry = zis.getNextEntry()) != null) { + String fileNameToUnzip = zentry.getName(); + File targetFile = new File(targetDir, fileNameToUnzip); + + if (zentry.isDirectory()) {// Directory 인 경우 + File newDir = new File(targetFile.getAbsolutePath()); + newDir.mkdirs(); + } else { // File 인 경우 + //parent Directory 생성 + File newFile = new File(targetFile.getParent()); + newFile.mkdirs(); + + fos = new FileOutputStream(targetFile); + byte[] buffer = new byte[1024]; + int len = 0; + + while ((len = zis.read(buffer)) != -1) { + fos.write(buffer, 0, len); + } + fos.close(); + } + } + + zis.close(); + fis.close(); + + }catch (FileNotFoundException e){ + log.error("FileNotFoundException Error"); + }catch (IOException e){ + log.error("IOException Error"); + }finally{ + + if (fos != null) { + try{ + fos.close(); + }catch (IOException e){ + log.error("IOException Error"); + } + } + + if (zis != null) { + try{ + zis.close(); + }catch (IOException e){ + log.error("IOException Error"); + } + } + + if (fis != null) { + try{ + fis.close(); + }catch (IOException e){ + log.error("IOException Error"); + } + } + } + } + + public static String getRandomData (int length) { + int index = 0; + char[] charSet = new char[] { + '0','1','2','3','4','5','6','7','8','9' + ,'A','B','C','D','E','F','G','H','I','J','K','L','M' + ,'N','O','P','Q','R','S','T','U','V','W','X','Y','Z' + ,'a','b','c','d','e','f','g','h','i','j','k','l','m' + ,'n','o','p','q','r','s','t','u','v','w','x','y','z'}; + + StringBuffer sb = new StringBuffer(); + for (int i=0; i 0){ + sb.append(charSet[index]); + } + } + + return sb.toString(); + } + + /** + * random한 값을 얻고자 할때 사용하는 메소드 + * 보안 관련 체크를 위해서 Math.random 이 아닌 SecureRandom을 이용해서 작업을 진행함 + * 결과 값이 min값보다 작은경우 rendom함수 재호출 해서 값을 넘겨주는 방식 + * @param int max 난수 최대값 + * @param int min 난수 최소값 + * @return int 난수값 + * */ + public static int getRandom(int max, int min){ + int result = 0; + SecureRandom ran = new SecureRandom(); + result = ran.nextInt(max); + return result < min ? getRandom(max,min) : result; + } + + public static String getSeedWE8DECtoKor(String strData){ + + //ex.) UTL_RAW.CAST_TO_RAW(columnName) + + if (strData.length() % 2 != 0) { + return ""; + } + + StringBuffer buff = new StringBuffer(); + + int i = 0; + + while( i < strData.length() ){ + buff.append((char)Integer.parseInt(strData.substring(i, i+2),16)); + i = i + 2; + } + + try{ + + if(buff.toString() != null){ + return new String(buff.toString().getBytes("8859_1"), "EUC_KR"); + }else{ + return buff.toString(); + } + + }catch(Exception ex){ + return ex.toString(); + } + } + + public static String setTagRemove(String strOriginal){ + + String strRemove = ""; + + if(strOriginal != null && !"".equals(strOriginal)){ + strRemove = strOriginal.replaceAll("<(/)?([a-zA-Z]*)(\\s[a-zA-Z]*=[^>]*)?(\\s)*(/)?>", ""); + } + + return strRemove; + } + + public static boolean setChkFilePath(String filePath){ + + boolean chk = false; + + if(filePath != null && !"".equals(filePath)){ + if(filePath.indexOf(".") >= 0){ + chk = true; + } + } + + return chk; + } + + public static Long getFolderSize(File file, Long volume){ + + File[] listFile = file.listFiles(); + + if(listFile != null && listFile.length > 0){ + + for(int i=0;i length){ + int chkLoop = 0; + for(int i=0; i= length){ + returnStr = returnStr + "..."; + break; + } + char ch = str.charAt(i); + Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.of(ch); + if(Character.UnicodeBlock.HANGUL_SYLLABLES.equals(unicodeBlock) || + Character.UnicodeBlock.HANGUL_JAMO.equals(unicodeBlock) || + Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO.equals(unicodeBlock)){ + returnStr = returnStr+String.valueOf(ch); + chkLoop = chkLoop+chkLen; + }else{ + returnStr = returnStr+String.valueOf(ch); + chkLoop = chkLoop+1; + } + } + }else{ + returnStr = str; + } + } + + return returnStr; + } + + public static String getJspContentTypeStr(){ + return "<%@ page language=\"java\" contentType=\"text/html; charset=UTF-8\" pageEncoding=\"UTF-8\"%>"; + } + + public static void setFileMkdirAuthSet(File dir){ + if(dir != null){ + dir.setExecutable(false, true); + dir.setReadable(true); + dir.setWritable(true, true); + } + } + + public static boolean getBrowserHtml5(String userAgent){ + + boolean success = true; + + //IE 버전일때 체크 + if(userAgent.indexOf("msie") > -1 || userAgent.indexOf("trident/") > -1){ + + //IE6, IE7은 Trident 없음 + if(userAgent.indexOf("trident/") <= -1){ + success = false; + }else{ + if(userAgent.indexOf("trident/5.0") > -1){ + //IE 9 + success = false; + }else if(userAgent.indexOf("trident/4.0") > -1){ + //IE 8 + success = false; + } + } + } + + return success; + } + + public static boolean getBrowserIE(String userAgent){ + + boolean success = false; + + //IE 버전일때 체크 + if(userAgent.indexOf("msie") > -1 || userAgent.indexOf("trident/") > -1){ + success = true; + } + + return success; + } + + /** + * long형태의 데이터를 int형태로 변경하는 메소드 + * 변경 실패시 IllegalArgumentException 발생 + * */ + public static int safeLongToInt(long l) { + int i = (int)l; + if ((long)i != l) { + throw new IllegalArgumentException(l + " safeLongToInt에서 에러 발생"); + } + return i; + } + + public static boolean isMobile(String userAgent){ + boolean isMobile = false; + userAgent = userAgent.toLowerCase(); + + String[] mobileKeyWord = {"iphone","ipod","android","blackberry","opera mini","opera mobi","skyfire","maemo","windows phone","palm","iemobile","symbian","symbianos","fennec"}; + for(int i=0; i-1){ + isMobile = true; + break; + } + } + return isMobile; + } + + public static boolean isTablet(String userAgent){ + boolean isTablet = false; + userAgent = userAgent.toLowerCase(); + String[] mobileKeyWord = {"ipad","android 3","sch-i800","playbook","tablet","kindle","gt-p1000","sgh-t849","shw-m180s","a510","a511","a100","dell streak","silk"}; + for(int i=0; i-1){ + isTablet = true; + break; + } + } + return isTablet; + } + + public static String encodeURIComponent(String s) { + String result = null; + try{ + result = URLEncoder.encode(s, "UTF-8") + .replaceAll("\\+", "%20") + .replaceAll("\\%21", "!") + .replaceAll("\\%27", "'") + .replaceAll("\\%28", "(") + .replaceAll("\\%29", ")") + .replaceAll("\\%7E", "~"); + }catch (UnsupportedEncodingException e){result = s;} + return result; + } + + public static boolean isCookieChk(String cookieKey, int cookieHour, HttpServletRequest request, HttpServletResponse response){ + + try { + + if(cookieHour == 0){ + return true; + } + + SeedCookieUtil seedCookieUtil = new SeedCookieUtil(); + + String cookieVal = seedCookieUtil.getCookie(request, cookieKey); + + if (!("Y".equals(cookieVal))) { + seedCookieUtil.setCookie(response, cookieHour * 24 * 60 * 60, "/", cookieKey, "Y", true); + return true; + } + + }catch (Exception localException){ + log.error("Exception localException"); + } + + return false; + } + +/* public static String getCpuInfo() { + + String cpuInfo = ""; + + Sigar sigar = new Sigar(); + + CpuPerc cpu; + + try { + cpu = sigar.getCpuPerc(); + cpuInfo = CpuPerc.format(cpu.getUser()); + } catch (SigarException e) { + log.error("CHECK ERROR:",e); + } + + return cpuInfo; + } + + public static String getMemoryInfo() { + + String memoryInfo = ""; + + Sigar sigar = new Sigar(); + + Mem mem; + try { + mem = sigar.getMem(); + memoryInfo = format(mem.getTotal()) + ":" + format(mem.getUsed()) + ":" + format(mem.getFree()); + } catch (SigarException e) { + log.error("CHECK ERROR:",e); + } + + return memoryInfo; + }*/ + + public static String format(Long value) { + return Long.toString(new Long(value / 1024)); + } +} \ No newline at end of file