Skip to content

Commit 7b5d2dd

Browse files
authored
Merge pull request #5 from toss/secure_random
java 1.6 utf8 대응
2 parents 67f9fc5 + 422438a commit 7b5d2dd

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ JAVA 1.8버전 사용자들을 위한 세션키 발급 및 개인정보 암복
66

77
예시)
88
```
9-
<version>0.0.5</version>
9+
<version>0.0.6</version>
1010
```
1111

1212
pom.xml 을 사용하시면 아래와 같이 추가해주세요.

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group 'com.github.toss'
9-
version '0.0.5'
9+
version '0.0.6'
1010

1111
sourceCompatibility = JavaVersion.VERSION_1_6
1212
targetCompatibility = JavaVersion.VERSION_1_6

src/main/java/im/toss/cert/sdk/AESCipher.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
import javax.crypto.spec.GCMParameterSpec;
88
import javax.crypto.spec.IvParameterSpec;
99
import javax.crypto.spec.SecretKeySpec;
10-
import java.nio.charset.StandardCharsets;
10+
import java.nio.charset.Charset;
1111
import java.security.InvalidAlgorithmParameterException;
1212
import java.security.InvalidKeyException;
1313
import java.security.NoSuchAlgorithmException;
1414
import java.security.spec.AlgorithmParameterSpec;
1515

1616
class AESCipher {
17+
private static final Charset charset = Charset.forName("UTF-8");
1718
private final SecretKeySpec secretKey;
1819
private final AlgorithmParameterSpec ivSpec;
1920
private final AESAlgorithm algorithm;
@@ -34,14 +35,14 @@ class AESCipher {
3435

3536
String encrypt(String plainText) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
3637
Cipher cipher = getCipher(Cipher.ENCRYPT_MODE);
37-
byte[] cipherText = cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8));
38+
byte[] cipherText = cipher.doFinal(plainText.getBytes(charset));
3839
return Base64Utils.encodeToString(cipherText);
3940
}
4041

4142
String decrypt(String encryptedText) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
4243
Cipher cipher = getCipher(Cipher.DECRYPT_MODE);
4344
byte[] cipherText = cipher.doFinal(Base64Utils.decode(encryptedText));
44-
return new String(cipherText, StandardCharsets.UTF_8);
45+
return new String(cipherText, charset);
4546
}
4647

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

0 commit comments

Comments
 (0)