언어 설정

Menu
Sites
Language
Tizen MD5 and SHA1 return wrong values [SOLVED]
Hi !
 
Similar problem was raised some time ago, but without any success.
I post this message to emphasize it again: MD5 and SHA1 return wrong values in Tizen (at least in Emulator).
 
For example, when trying a string 'test':
Tizen MD5      = e2a3e68d23ce348b8f68b3079de3d4c9      
but should be = 098f6bcd4621d373cade4e832627b4f6
 
Tizen SHA1     = 961fa64958818f767707072755d7018dcd278e94
but should be = a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
 
Tizen gurus, please help!
Edited by: Serhii Kolomiiets on 20 9월, 2013

Responses

5 댓글
youngsik yoon
please don't forget to call SetLimit(buffer_limit - 1) after getting ByteBuffer from StringToUtf8N(). e.g.
String test(L"test");
ByteBuffer* out = StringUtil::StringToUtf8N(test);
out->SetLimit(out->GetCapacity() - 1);
according to dev guide, StringToUtf8N() function returns ByteBuffer and "The buffer's limit is the length of the string plus one and the starting position is 0". so your buffer should be "-1"
Serhii Kolomiiets
Eureka, it works now ! Thanks, man!
Levan Gogohia
Give me please your code with md5, i dont know how to include this((
Serhii Kolomiiets

Hi, Levan !

voila:

String XXXXXXXXXXX::LeftPadZero(String s, int wantedLen) {
    int prependCount = (wantedLen - s.GetLength()); 
    if (prependCount <= 0) return s; // nothing to do
    //==
    String sPreffix = "0";
    for (int i=1; i < prependCount; i++) sPreffix = "0" + sPreffix;
    return sPreffix + s;
}


// hashing
String XXXXXXXXXXX::MD5(String s) {
    ByteBuffer* pInput = StringUtil::StringToUtf8N(s);
    pInput->SetLimit(pInput->GetCapacity() - 1);

    Md5Hash md5;
    ByteBuffer* pOutput = md5.GetHashN(*pInput);
    String sHash;

    {
        int byteCount = pOutput->GetLimit();

        for (int i = 0; i < byteCount; i++) {
            byte b;  pOutput -> GetByte(i, b);
            unsigned int ui = b;
            String sHex;
            sHex.Format(25, L"%02x", ui);
            sHash.Append(sHex);
        }
    }

    delete pInput;
    delete pOutput;

    // should return 32 bytes
    sHash = LeftPadZero(sHash, 32);

    ///
    return sHash;
}

 

Levan Gogohia

Thanx:-)  this is working:-)