언어 설정

Menu
Sites
Language
Difference in MD5 hash generated by the terminal and with API GetHashN of IHash interface

Hi,

I am genarating a MD5 Hash for a certain text input and found that the hash generated was not similar to that of the terminal command.

So i tried a sample code to generate a hash for sample string "test"

 I am using the following command on terminal of the device

echo "test" | md5sum

the hash generated is d8e8fca2dc0f896fd7cb4cb0031ba249

 

In my application the code is as below

String inputStr(L"test");

IHash* pHash = new Md5Hash();

Tizen::Text::Utf8Encoding utf8Enc;

ByteBuffer* pInput = utf8Enc.GetBytesN(inputStr);
pOutput = pHash->GetHashN(*pInput);

this generates a hash e2a3e68d23ce348b8f68b379de3d4c9

Please let me know the procedure to obtain the same MD5 hast for the input both in code and terminal.

 

Thanks & Regards

 

 
Edited by: Brock Boland on 17 3월, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

5 댓글
john Smith
Hi, Can you share some little code snippet, how you generate MD5 Hash for certain string.
Serhii Kolomiiets
Hey, Suneel! I have another problems with MD5 - I can't transform received ByteBuffer in readable string. Even when trying official examples (e.g. https://developer.tizen.org/documentation/articles/overview-encoding-and-decoding-text-tizen. ) I receive either fatal exception or other errors like: static Tizen::Text::_EncodingCore* Tizen::Text::_Ucs2EncodingCore::GetEncodingCoreImplN(const Tizen::Base::String&, const Tizen::Base::String&)(60) > [E_UNSUPPORTED_TYPE] It is not the UCS2 type. virtual wchar_t* Tizen::Text::_IcuEncodingCore::DecodeN(const byte*, int, int&)(344) > [E_INVALID_ENCODING_RANGE] Encode operation failed please share your MD5 generation code, please. thanks!
Serhii Kolomiiets
Link to example have dot symbol at the end! .....n/articles/overview-encoding-and-decoding-text-tizen. <<< !!!!! see the dot
Serhii Kolomiiets
String sHash; int byteCount = pOutput->GetLimit(); // dump bytes for (int i = 0; i < byteCount; i++) { byte b; pOutput -> GetByte(i, b); String sHex; sHex.Format(25, L"%x", b); sHash.Append(sHex); } for string "test" I receive MD5 "e2a3e68d23ce348b8f68b379de3d4c9" whereas in real it should be "098f6bcd4621d373cade4e832627b4f6". wtf ?
youngsik yoon
you should use below command to get right md5 value.
echo -n "test" | md5sum
and in the code, need to set buffer limit using SetLimit() of ByteBuffer. please refer to https://developer.tizen.org/forums/native-application-development/tizen-md5-and-sha1-return-wrong-values