diff --git a/README.md b/README.md index 8751749..30e420c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ JAVA 1.8버전 사용자들을 위한 세션키 발급 및 개인정보 암복 예시) ``` -0.0.10 +0.0.11 ``` pom.xml 을 사용하시면 아래와 같이 추가해주세요. diff --git a/build.gradle b/build.gradle index 62bd4bb..3d166ac 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group 'com.github.toss' -version '0.0.10' +version '0.0.11' sourceCompatibility = JavaVersion.VERSION_1_6 targetCompatibility = JavaVersion.VERSION_1_6 diff --git a/src/main/java/im/toss/cert/sdk/TossCertSession.java b/src/main/java/im/toss/cert/sdk/TossCertSession.java index 03405b3..2d01076 100644 --- a/src/main/java/im/toss/cert/sdk/TossCertSession.java +++ b/src/main/java/im/toss/cert/sdk/TossCertSession.java @@ -1,5 +1,9 @@ package im.toss.cert.sdk; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -42,8 +46,18 @@ public String encrypt(String plainText) { String encrypted = aesCipher.encrypt(plainText); String hash = calculateHash(plainText); return addMeta(StringUtils.join(separator, new String[]{encrypted, hash})); - } catch (Exception e) { - throw new RuntimeException(e); + } catch (InvalidAlgorithmParameterException e) { + throw new RuntimeException(e.getCause()); + } catch (NoSuchPaddingException e) { + throw new RuntimeException(e.getCause()); + } catch (IllegalBlockSizeException e) { + throw new RuntimeException(e.getCause()); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e.getCause()); + } catch (BadPaddingException e) { + throw new RuntimeException(e.getCause()); + } catch (InvalidKeyException e) { + throw new RuntimeException(e.getCause()); } } @@ -62,8 +76,18 @@ public String decrypt(String encryptedText) { String plainText = aesCipher.decrypt(items[2]); verify(plainText, items); return plainText; - } catch (Exception e) { - throw new RuntimeException(e); + } catch (InvalidAlgorithmParameterException e) { + throw new RuntimeException(e.getCause()); + } catch (NoSuchPaddingException e) { + throw new RuntimeException(e.getCause()); + } catch (IllegalBlockSizeException e) { + throw new RuntimeException(e.getCause()); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e.getCause()); + } catch (BadPaddingException e) { + throw new RuntimeException(e.getCause()); + } catch (InvalidKeyException e) { + throw new RuntimeException(e.getCause()); } } diff --git a/src/main/java/im/toss/cert/sdk/TossCertSessionGenerator.java b/src/main/java/im/toss/cert/sdk/TossCertSessionGenerator.java index 74ec1f9..ada5550 100644 --- a/src/main/java/im/toss/cert/sdk/TossCertSessionGenerator.java +++ b/src/main/java/im/toss/cert/sdk/TossCertSessionGenerator.java @@ -5,10 +5,11 @@ import javax.crypto.NoSuchPaddingException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; +import java.security.spec.InvalidKeySpecException; import java.util.UUID; public class TossCertSessionGenerator { - private final static String version = "v1_0.0.10"; + private final static String version = "v1_0.0.11"; private final static String publicKey = "MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAoVdxG0Qi9pip46Jw9ImSlPVD8+L2mM47ey6EZna7D7utgNdh8Tzkjrm1Yl4h6kPJrhdWvMIJGS51+6dh041IXcJEoUquNblUEqAUXBYwQM8PdfnS12SjlvZrP4q6whBE7IV1SEIBJP0gSK5/8Iu+uld2ctJiU4p8uswL2bCPGWdvVPltxAg6hfAG/ImRUKPRewQsFhkFvqIDCpO6aeaR10q6wwENZltlJeeRnl02VWSneRmPqqypqCxz0Y+yWCYtsA+ngfZmwRMaFkXcWjaWnvSqqV33OAsrQkvuBHWoEEkvQ0P08+h9Fy2+FhY9TeuukQ2CVFz5YyOhp25QtWyQI+IaDKk+hLxJ1APR0c3tmV0ANEIjO6HhJIdu2KQKtgFppvqSrZp2OKtI8EZgVbWuho50xvlaPGzWoMi9HSCb+8ARamlOpesxHH3O0cTRUnft2Zk1FHQb2Pidb2z5onMEnzP2xpTqAIVQyb6nMac9tof5NFxwR/c4pmci+1n8GFJIFN18j2XGad1mNyio/R8LabqnzNwJC6VPnZJz5/pDUIk9yKNOY0KJe64SRiL0a4SNMohtyj6QlA/3SGxaEXb8UHpophv4G9wN1CgfyUamsRqp8zo5qDxBvlaIlfkqJvYPkltj7/23FHDjPi8q8UkSiAeu7IV5FTfB5KsiN8+sGSMCAwEAAQ=="; private final RSACipher rsaCipher; @@ -20,8 +21,10 @@ public TossCertSessionGenerator() { public TossCertSessionGenerator(String publicKeyString) { try { this.rsaCipher = new RSACipher(publicKeyString); - } catch (Exception e) { - throw new RuntimeException(e); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e.getCause()); + } catch (InvalidKeySpecException e) { + throw new RuntimeException(e.getCause()); } } @@ -53,8 +56,16 @@ private TossCertSession generate(AESAlgorithm algorithm, int keyLength, int ivLe } String encryptedSessionKey = buildEncryptSessionKeyPart(algorithm, secretKey, iv); return new TossCertSession(version, id, algorithm, secretKey, iv, encryptedSessionKey); - } catch (Exception e) { - throw new RuntimeException(e); + } catch (NoSuchPaddingException e) { + throw new RuntimeException(e.getCause()); + } catch (IllegalBlockSizeException e) { + throw new RuntimeException(e.getCause()); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e.getCause()); + } catch (BadPaddingException e) { + throw new RuntimeException(e.getCause()); + } catch (InvalidKeyException e) { + throw new RuntimeException(e.getCause()); } } @@ -66,8 +77,16 @@ public TossCertSession deserialize(String serializedSessionKey) { String iv = fields[4]; String encryptedSessionKey = buildEncryptSessionKeyPart(algorithm, secretKey, iv); return new TossCertSession(fields[0], fields[1], algorithm, secretKey, iv, encryptedSessionKey); - } catch (Exception e) { - throw new RuntimeException(e); + } catch (NoSuchPaddingException e) { + throw new RuntimeException(e.getCause()); + } catch (IllegalBlockSizeException e) { + throw new RuntimeException(e.getCause()); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e.getCause()); + } catch (BadPaddingException e) { + throw new RuntimeException(e.getCause()); + } catch (InvalidKeyException e) { + throw new RuntimeException(e.getCause()); } }