Symbian3/SDK/Source/GUID-D88AA184-6E22-5069-A249-5AD83F548C56.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Tue, 20 Jul 2010 12:00:49 +0100
changeset 13 48780e181b38
parent 0 89d6a7a84779
permissions -rw-r--r--
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept xml:lang="en" id="GUID-D88AA184-6E22-5069-A249-5AD83F548C56"><title>How to use the Hash API</title><prolog><metadata><keywords/></metadata></prolog><conbody><ul><li id="GUID-019D2F91-38B5-5D35-B16F-F64E20188E8B"><p><xref href="GUID-D88AA184-6E22-5069-A249-5AD83F548C56.dita#GUID-D88AA184-6E22-5069-A249-5AD83F548C56/GUID-DEE9EA04-A6FD-5BE2-A26F-55126414FAC3">How do I use the hash framework?</xref>  </p> </li> <li id="GUID-6BDA9DDE-F26C-5E49-91D5-6F1CA81656E3"><p><xref href="GUID-D88AA184-6E22-5069-A249-5AD83F548C56.dita#GUID-D88AA184-6E22-5069-A249-5AD83F548C56/GUID-AF3925CF-E372-56A4-A473-FF583F92AD08">Which hash should I use?</xref>  </p> </li> </ul> <section id="GUID-DEE9EA04-A6FD-5BE2-A26F-55126414FAC3"><title>How do I use the hash framework?</title> <p>There are a couple of ways to interact with the hash framework. The following example is probably the most common: </p> <codeblock id="GUID-CECDA431-7E5D-530C-A6DE-273F8A33B530" xml:space="preserve"> 
_LIT(messagePart1, "Hello ");
_LIT(messagePart2, "My "); 
_LIT(messagePart3, "Name "); 
_LIT(messagePart4, "is Fred"); 
TBuf8&lt;20&gt; hash;

CSHA1* sha1 = CSHA1::NewL(); 
sha1-&gt;Update(messagePart1);
sha1-&gt;Update(messagePart2); 
sha1-&gt;Update(messagePart3);
hash.Copy(sha1-&gt;Final(messagePart4)); 
</codeblock> <p>Note that <codeph>Final()</codeph> has a version that takes no data parameter which may be useful in certain situations. </p> <p>A few pointers: </p> <ul><li id="GUID-A9716705-015A-5AFD-A038-BAB3F8D4C4DA"><p>You can reuse a hash object by calling <codeph>Reset()</codeph>. </p> </li> <li id="GUID-90C1BB63-563B-52D7-9B27-E3D638E00BA7"><p>Both versions of <codeph>Final()</codeph> call <codeph>Reset()</codeph> at the end of their function automatically. </p> </li> <li id="GUID-72D8B74B-CCAD-513B-951E-E06101644EA3"><p>Be aware that the returned <codeph>TPtrC8</codeph> from <codeph>Final()</codeph> points to an internal buffer. Calling <codeph>Update()</codeph> or <codeph>Final()</codeph> again changes the contents of this buffer and will destroy your previously computed hash. As in the example above, make sure you copy the data out if you need it. </p> </li> </ul> </section> <section id="GUID-AF3925CF-E372-56A4-A473-FF583F92AD08"><title>Which hash should I use?</title> <p>Unless you have a specific need to support certain hashes, use SHA-1. </p> </section> </conbody></concept>