Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Symbian OS v9上信息摘要算法的实现(MD5/SHA1)

From Wiki
Jump to: navigation, search
Article Metadata

beover1984 在 09 Aug 2007 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

在涉及安全方面的应用时我们通常都会用到数字签名技术,并且大多都是通过MD5或SHA1信息摘要算法实现,在Series 60 2nd及以前的版本没有公开这方面的API,我们只能按照RFC文档上的C语言算法实现进行移植, 当然移植起来并不困难.Symbian OS v9发布后使事情变得更简单了,它公开了一些安全方面的API,下面就以CMD5为例展示如何进行MD5信息摘要:

void GetMsgDigestByMd5L( TDes8 &aDest, const TDesC8 &aSrc )
_LIT8( KDigestFormat, "%02x" );
CMD5 *md5 = CMD5::NewL();
CleanupStack ::PushL( md5 );
TPtrC8 ptrHash = md5->Hash( aSrc );
for( TInt i=0; i < ptrHash.Length(); i++ )
aDest.AppendFormat( KDigestFormat, ptrHash[i] );
CleanupStack::PopAndDestroy( md5 );

短短几行代码就完成了MD5信息摘要的功能,确实很简单吧:)当然我们还可以使用CMD5:: Update()不断增加信息内容以实现对大量数据的信息摘要功能.使用CMD5,我们需要包含头文件hash.h,并需要链接hash.lib,另外SHA1的实现方法和上面类似,只需把CMD5替换成CSHA1这个类就可以了.

This page was last modified on 15 December 2011, at 10:05.
98 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.