Md5 는 해쉬함수로 평문(plain text)을 입력하면 128bit(32글자) 고정크기로 암호화 해주는 해쉬 알고리즘으로 이론적으로는 복호화 될 수 없다. 그러나 Md5 자체의 수학적 오류로 이 약점을 이용해서 복호화가 가능하다고 인터넷에 나오는데 실제로 확인은 못해보았지만 안전하지 않은 것으로 추정된다. 그리고 무조건 32글자로 암호화 되기 때문에 1byte는 절대로 만들 수 없다. 아래는 md5 해쉬코드 암호화를 android studio 에서 구현해본 source code 이다.
public static String getEncMD5(String message) throws Exception {
MessageDigest digest =
MessageDigest.getInstance("MD5");
byte[] hashedBytes = digest.digest(message.getBytes("UTF-8"));
return convertByteArrayToHexString(hashedBytes);
}
private static String convertByteArrayToHexString(byte[] arrayBytes) {
StringBuffer
stringBuffer = new StringBuffer();
for (int i = 0; i < arrayBytes.length; i++) {
stringBuffer.append(Integer.toString((arrayBytes[i] & 0xff) + 0x100, 16)
.substring(1));
}
return stringBuffer.toString();
}
// test
@Override
protected void onCreate(Bundle savedInstanceState) {
try {
String md5 = SMUtils.getEncMD5("md5tech");
Log.d("test", "[onCreate:md5 >>>>> " +md5);
} catch (Exception e) {
e.printStackTrace();
}
}
//result
06-14 16:47:54.345 21621-21621/com.juntcompany.practice1bluetooth D/test: [onCreate:md5 >>>>> be201ff78925af48b1d386feb7c3e964
Ø 결과값 글자세보면 32글자 나옴