diff --git a/src/main/java/cokr/xit/base/security/access/ApplicationAccess.java b/src/main/java/cokr/xit/base/security/access/ApplicationAccess.java index e676582..df1d81e 100644 --- a/src/main/java/cokr/xit/base/security/access/ApplicationAccess.java +++ b/src/main/java/cokr/xit/base/security/access/ApplicationAccess.java @@ -23,9 +23,7 @@ import cokr.xit.foundation.Access; * @author mjkhan */ @Component("applicationAccess") -public class ApplicationAccess - extends AbstractComponent - implements AccessDecisionVoter, AuthorizationManager { +public class ApplicationAccess extends AbstractComponent implements AccessDecisionVoter, AuthorizationManager { /** 권한별 가용 기능(URL) */ @Resource(name="accessContext") protected AccessContext accessContext; diff --git a/src/main/java/cokr/xit/base/security/crypto/Encryptor.java b/src/main/java/cokr/xit/base/security/crypto/Encryptor.java deleted file mode 100644 index a1ec873..0000000 --- a/src/main/java/cokr/xit/base/security/crypto/Encryptor.java +++ /dev/null @@ -1,80 +0,0 @@ -package cokr.xit.base.security.crypto; - -import java.security.Key; -import java.util.Base64; - -import javax.crypto.Cipher; -import javax.crypto.spec.IvParameterSpec; - -import cokr.xit.foundation.AbstractComponent; - -public class Encryptor extends AbstractComponent { - private String algorithm; - private Key key; - private IvParameterSpec iv; - private Cipher cipher; - - /**알고리즘을 반환한다. - * @return 알고리즘 - */ - public String getAlgorithm() { - return algorithm; - } - - /**알고리즘을 설정한다. - * @param algorithm 알고리즘 - * @return Encryptor - */ - public Encryptor setAlgorithm(String algorithm) { - this.algorithm = algorithm; - return this; - } - - /**SecretKey를 반환한다. - * @return SecretKey - */ - public Key getKey() { - return key; - } - - /**SecretKey를 설정한다. - * @param key SecretKey - * @return Encryptor - */ - public Encryptor setKey(Key key) { - this.key = key; - return this; - } - - /**iv를 반환한다. - * @return iv - */ - public IvParameterSpec getIv() { - return iv; - } - - /**iv를 설정한다. - * @param iv iv - * @return Encryptor - */ - public Encryptor setIv(IvParameterSpec iv) { - this.iv = iv; - return this; - } - - public String encrypt(String str) { - if (isEmpty(str)) return ""; - - try { - if (cipher == null) { - cipher = Cipher.getInstance(algorithm); - cipher.init(Cipher.ENCRYPT_MODE, key, iv); - } - byte[] cipherText = cipher.doFinal(str.getBytes()); - return Base64.getEncoder() - .encodeToString(cipherText); - } catch (Exception e) { - throw applicationException(e); - } - } -} \ No newline at end of file diff --git a/src/main/java/cokr/xit/base/security/crypto/KeyFactory.java b/src/main/java/cokr/xit/base/security/crypto/KeyFactory.java deleted file mode 100644 index dbd1858..0000000 --- a/src/main/java/cokr/xit/base/security/crypto/KeyFactory.java +++ /dev/null @@ -1,85 +0,0 @@ -package cokr.xit.base.security.crypto; - -import java.security.Key; -import java.security.SecureRandom; -import java.security.spec.KeySpec; -import java.util.List; - -import javax.crypto.KeyGenerator; -import javax.crypto.SecretKeyFactory; -import javax.crypto.spec.IvParameterSpec; -import javax.crypto.spec.PBEKeySpec; -import javax.crypto.spec.SecretKeySpec; - -import cokr.xit.foundation.AbstractComponent; - -public class KeyFactory extends AbstractComponent { - private int keySize; - private String algorithm; - private KeyGenerator keyGen; - - /**키 사이즈를 반환한다. - * @return 키 사이즈 - */ - public int getKeySize() { - return Math.max(128, keySize); - } - - /**키 사이즈를 설정한다. - * @param keySize 키 사이즈(128, 192, 또는 256 비트) - * @return KeyFactory - */ - public KeyFactory setKeySize(int keySize) { - if (!List.of(128, 192, 256).contains(keySize)) - throw new IllegalArgumentException("keySize must be either of 128, 192, 256"); - - this.keySize = keySize; - return this; - } - - /**알고리즘을 반환한다. - * @return 알고리즘 - */ - public String getAlgorithm() { - return ifEmpty(algorithm, "AES"); - } - - /**알고리즘을 설정한다. - * @param algorithm 알고리즘 - * @return KeyFactory - */ - public KeyFactory setAlgorithm(String algorithm) { - this.algorithm = algorithm; - return this; - } - - public static IvParameterSpec generateIv(int size) { - byte[] iv = new byte[size]; - new SecureRandom().nextBytes(iv); - return new IvParameterSpec(iv); - } - - public Key create() { - try { - if (keyGen == null) { - keyGen = KeyGenerator.getInstance(getAlgorithm()); - keyGen.init(getKeySize()); - } - return keyGen.generateKey(); - } catch (Exception e) { - throw applicationException(e); - } - } - - public Key create(String str, String salt) { - if (isEmpty(str) || isEmpty(salt)) return null; - - try { - SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256"); - KeySpec spec = new PBEKeySpec(str.toCharArray(), salt.getBytes(), 65536, getKeySize()); - return new SecretKeySpec(skf.generateSecret(spec).getEncoded(), getAlgorithm()); - } catch (Exception e) { - throw applicationException(e); - } - } -} \ No newline at end of file