decrypt에 사용하는 클래스 : Cipher
decrypt 과정
SecretKeySpec keySpec = new SecretKeySpec(keyArr, "AES");
// AES 암호화 알고리즘으로 Cipher 초기화
Cipher cipher = Cipher.getInstance("AES");
// decrypt 모드로, 비밀키를 keySpec으로 지정
cipher.init(Cipher.DECRYPT_MODE, keySpec);
// 복호화 진행(doFinal)
byte[] decBytes = cipher.doFinal(toByte(source));
여기서 중요한점은 SecretKey 설정인데,
secretKey가 왔다고 그걸 그대로 getByte()로 변환해서는 안된다.
public static byte[] toByte(String hex) {
byte[] ba = new byte[hex.length() / 2];
for(int i = 0; i < ba.length; i++) {
ba[i] = (byte)Integer.parseInt(hex.substring(2 * i, 2 * i + 2), 16);
}
return ba;
}
'프로그래밍 > Android 짜투리 지식' 카테고리의 다른 글
| [android] toast text 위치 (0) | 2013.01.16 |
|---|---|
| [android] db asset경로에서 참조하기 (0) | 2012.12.07 |
| [android] FragmentActivity - Fragment 에 하드웨어 키 리스너 가져오기 (0) | 2012.11.26 |
| [android] sdcard 내 image 검색 (0) | 2012.11.17 |
| [android] selector (0) | 2012.11.05 |