Sunday, October 28, 2007

MD5 HexDigest for Symbian

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();

TPtrC8 hashedSig(md5->Hash(aString));

HBufC8* buf = HBufC8::NewL(hashedSig.Length() * 2);
TPtr8 bufPtr = buf->Des();

for(TInt i=0; i< hashedSig.Length(); i++)
return buf;

No comments:

stats counter