Android/자료정리
[Android][SEED CBC] 암복호화 처리
썩소천사
2021. 7. 30. 16:57
반응형
예전에 JAVA 버전 SEED CBC가 없었던 것 같은데...
다시 사용하려고 다운받아보니 있다.
그런김에 암복호화 매서드 정리!
1. 파일 다운로드
https://seed.kisa.or.kr/kisa/Board/17/detailView.do
2. key, iv 셋팅
1
2
3
4
5
6
|
public static final byte[] key = new String("1234567890123456").getBytes();
public static final byte[] iv = {
(byte) 0x26, (byte) 0x8D, (byte) 0x66, (byte) 0xA7, (byte) 0x35, (byte) 0xA8,
(byte) 0x1A, (byte) 0x81, (byte) 0x6F, (byte) 0xBA, (byte) 0xD9, (byte) 0xFA,
(byte) 0x36, (byte) 0x16, (byte) 0x25, (byte) 0x01
};
|
cs |
3. 암호화, 복호화 매서드 추가
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
public static String DecryptString(String cText) {
Base64.Decoder decoder = Base64.getDecoder();
byte[] enc = decoder.decode(cText);
String result = "";
byte[] dec = null;
try {
dec = KISA_SEED_CBC.SEED_CBC_Decrypt( key, iv, enc, 0, enc.length);
result = new String(dec, ENCODING);
} catch (UnsupportedEncodingException e) {
Log.e("TAG", "UnsupportedEncodingException: " + e );
}
return result;
}
public static String EncryptString(String str) {
byte[] enc = null;
try {
enc = KISA_SEED_CBC.SEED_CBC_Encrypt( key, iv, str.getBytes(ENCODING), 0, str.getBytes(ENCODING).length);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Base64.Encoder encoder = Base64.getEncoder();
byte[] encArray = encoder.encode(enc);
String result = "";
try {
result = new String(encArray, ENCODING);
} catch (UnsupportedEncodingException e) {
Log.e("TAG", "UnsupportedEncodingException: " + e );
}
return result;
}
|
cs |
반응형