PrevNextUpHome SophiaFramework UNIVERSE 5.3
SFBHash
Wrapper Class for the IHash interface.
#include <SFBHash.h.hpp>
class SFBHash : public SFBBase;
SFMTYPEDEFWRAPPER(SFBHash)

Inheritance diagram

 Inheritance diagram of SFBHashClass

Version

BREW 2.0 BREW 2.1 BREW 3.1 BREW 4.0
O O O O

Reference

BREW API IHash

Member

Public Functions
SFCError GetResult( VoidPtr data , SInt32Ptr size )
Get the hashed result after all the calls to SFBHash::Update().
SFCError GetResult( SFXBufferPtr data )
Get the hashed result after all the calls to SFBHash::Update().
static
SFBHashSmp
NewInstance( AEECLSID clsid = AEECLSID_MD5 , SFCErrorPtr exception = null )
Create a new SFBHash instance.
Void Restart( Void )
Start a new hash.
SFCError SetKey( VoidConstPtr key , SInt32 keySize )
Initializes key for HMAC keyed hashes.
SFCError SetKey( SFXBufferConstRef key )
Initializes key for HMAC keyed hashes.
Void Update( VoidPtr data , SInt32 dataLength )
Feed data to the hash object.
Void Update( SFXBufferPtr data )
Feed data to the hash object.
Protected Functions
static
SFBBaseSmp
FactoryByCreate( AEECLSID id , SFCErrorPtr exception = null ) (inherits from SFBBase)
Create the instance for the specified ClassID's interface.
static
SFBBaseSmp
FactoryByQuery( SFBQuerySmpConstRef query , AEECLSID id , SFCErrorPtr exception = null ) (inherits from SFBBase)
Create the instance for the specified ClassID's interface using the SFBQuery instance.

SFBHash::GetResult
Get the hashed result after all the calls to SFBHash::Update().
[ public ]
SFCError GetResult(
    VoidPtr data     // pointer to the data to get the hashed result
    SInt32Ptr size   // pointer to the size of the buffer pbData. 
                     // on return, this contains the size of the hashed result
);
[ public ]
SFCError GetResult(
    SFXBufferPtr data   // pointer to the data to get the hashed result.
                        // the size of the buffer can be modified automatically
);

Description

Warning: Buffer size can not over the limit of a SInt32 value.

Reference

BREW API IHASH_GetResult


SFBHash::NewInstance
Create a new SFBHash instance.
[ public, static ]
SFBHashSmp NewInstance(
    AEECLSID clsid = AEECLSID_MD5   // ClassID for the Hash algorithm
    SFCErrorPtr exception = null    // Error
);

Description

The available ClassID is as below.

AEECLSID_MD2
AEECLSID_MD5
AEECLSID_SHA1

SFBHash::Restart
Start a new hash.
[ public ]
Void Restart(Void);

Description

New data stream needs to be hashed.

Example

Hash different data streams continuously, and show the log.

AChar     srcString[]     = {"message for you..."};
AChar     srcStringNext[] = {"next message for you..."};
AChar     result[32]      = {0};
SInt32    len             = 32;

// create new SFBHash instance.
SFBHashSmp  hash = SFBHash::NewInstance();

// hash.
hash->Update(srcString, STRLEN(srcString));

// get the result.
hash->GetResult(result, &len);

// show the results in log.
DBGPRINTF("*** result: %s ***", result);

// hash again.
ZEROAT(result);
len = 32;

// reset the data stream.
hash->Restart();

// hash byte by byte.
ACharPtr i = srcStringNext;
for (; *i; i++)
    hash->Update(i, 1);

// get the result.
hash->GetResult(result, &len);

// show the results in log.
DBGPRINTF("*** next result: %s ***", result);

Reference

BREW API IHASH_Restart


SFBHash::SetKey
Initializes key for HMAC keyed hashes.
[ public ]
SFCError SetKey(
    VoidConstPtr key   // Pointer to key 
    SInt32 keySize     // key size in bytes
);
[ public ]
SFCError SetKey(
    SFXBufferConstRef key   // Pointer to key
);

Return value

  • SUCCESS: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMORY
  • If key is invalid : AEE_CRYPT_INVALID_KEY

Version

Introduced in BREW 3.1

Description

[Caution] Caution

Calling this function on earlier versions of BREW 3.1 will cause your app to crash.

Reference

BREW API IHASH_SetKey


SFBHash::Update
Feed data to the hash object.
[ public ]
Void Update(
    VoidPtr data        // pointer to the data to be hashed
    SInt32 dataLength   // length of the data to be hashed(stored in data) 
);
[ public ]
Void Update(
    SFXBufferPtr data   // pointer to the data to be hashed.
                        // if null, do nothing
);

Description

This function can be called multiple times to hash long streams or discontinous streams of data.

Example

Hash a stream, show results in log.

AChar     srcString[] = {"message for you..."};
AChar     result[32]  = {0};
SInt32    len         = 32;

// create new instance of SFBHash cLass.
SFBHashSmp  hash = SFBHash::NewInstance();

// hash.
hash->Update(srcString, STRLEN(srcString));

// get the result.
hash->GetResult(result, &len);

// show the result in log.
DBGPRINTF("*** result: %s ***", result);

Reference

BREW API IHASH_Update