SymbianOS provides a CMD5 class for hashing 8-bit strings, but neglects to supply a hexdigest function to supply the Hash as a hex string, as required by many web services such as Flickr.
Calling CMD5::Hash() returns an 8bit binary descriptor of the hash. This snippet of code provides the HEX representation in ASCII in line with what HexDigest() returns in java and python etc.
HBufC8* Md5HexDigestLC(const TDes8& aString)
{
CMD5* md5 = CMD5::NewL();
CleanupStack::PushL(md5);
TPtrC8 hashedSig(md5->Hash(aString));
HBufC8* buf = HBufC8::NewL(hashedSig.Length() * 2);
TPtr8 bufPtr = buf->Des();
for(TInt i=0; i< hashedSig.Length(); i++)
{
bufPtr.AppendFormat(_L8("%+02x"),hashedSig[i]);
}
CleanupStack::PopAndDestroy(md5);
CleanupStack::PushL(buf);
return buf;
}
No comments:
Post a Comment