Skip to content

Commit

Permalink
Merge pull request #5 from toss/secure_random
Browse files Browse the repository at this point in the history
java 1.6 utf8 대응
  • Loading branch information
kaifer authored Jun 20, 2022
2 parents 67f9fc5 + 422438a commit 7b5d2dd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ JAVA 1.8버전 사용자들을 위한 세션키 발급 및 개인정보 암복

예시)
```
<version>0.0.5</version>
<version>0.0.6</version>
```

pom.xml 을 사용하시면 아래와 같이 추가해주세요.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group 'com.github.toss'
version '0.0.5'
version '0.0.6'

sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/im/toss/cert/sdk/AESCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.nio.charset.Charset;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.AlgorithmParameterSpec;

class AESCipher {
private static final Charset charset = Charset.forName("UTF-8");
private final SecretKeySpec secretKey;
private final AlgorithmParameterSpec ivSpec;
private final AESAlgorithm algorithm;
Expand All @@ -34,14 +35,14 @@ class AESCipher {

String encrypt(String plainText) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
Cipher cipher = getCipher(Cipher.ENCRYPT_MODE);
byte[] cipherText = cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8));
byte[] cipherText = cipher.doFinal(plainText.getBytes(charset));
return Base64Utils.encodeToString(cipherText);
}

String decrypt(String encryptedText) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
Cipher cipher = getCipher(Cipher.DECRYPT_MODE);
byte[] cipherText = cipher.doFinal(Base64Utils.decode(encryptedText));
return new String(cipherText, StandardCharsets.UTF_8);
return new String(cipherText, charset);
}

private Cipher getCipher(int opMode) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException {
Expand Down

0 comments on commit 7b5d2dd

Please sign in to comment.