2010년 12월 2일 목요일

bada에서 md5 hash 구하기

const char* DhrUtils::GetMd5N(const char* str)
{
Md5Hash md5;
ByteBuffer* byteText = new ByteBuffer();
byteText->Construct(strlen(str) + 1);
byteText->SetArray((byte*)str, 0, strlen(str));
byteText->SetByte(strlen(str), '\0');
byteText->Flip();
AppLog("position %d, limit %d, capacity %d", byteText->GetPosition(), byteText->GetLimit(), byteText->GetCapacity());
ByteBuffer* byteMd5Text = md5.GetHashN(*byteText);
const byte* pActualOutput = byteMd5Text->GetPointer();

String id;
id.Format(33, L"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
pActualOutput[0], pActualOutput[1], pActualOutput[2], pActualOutput[3],
pActualOutput[4], pActualOutput[5], pActualOutput[6], pActualOutput[7],
pActualOutput[8], pActualOutput[9], pActualOutput[10], pActualOutput[11],
pActualOutput[12], pActualOutput[13], pActualOutput[14], pActualOutput[15]);

char* ret = new char[33];
memset(ret, '\0', 33);
AppLog("MD5: %ls", id.GetPointer());
snprintf(ret, 33, "%ls", id.GetPointer());

delete byteMd5Text;
delete byteText;

return ret;
}

댓글 없음:

댓글 쓰기