class KMD5

# class KMD5 | An adapted C++ implementation of RSA Data Securities MD5 algorithm. More...
Definition | `#include <kmdcodec.h>`
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

#### Public Methods

- KMD5 ()
- KMD5 (const char* in, int len = -1)
- KMD5 (const QByteArray& a )
- KMD5 (const QCString& a )
- void update (const char* in, int len = -1)
- void update (const unsigned char* in, int len = -1)
- void update (const QByteArray& in )
- void update (const QCString& in )
- bool update (QIODevice& file)
- void reset ()
- const Digest& rawDigest ()
- void rawDigest ( KMD5::Digest& bin )
- QCString hexDigest ()
- void hexDigest (QCString&)
- QCString base64Digest ()
- bool verify ( const KMD5::Digest& digest)
- bool verify (const QCString&)

#### Public Members

- typedef unsigned char Digest[16]

#### Protected Methods

- void transform ( const unsigned char buffer[64] )
- void finalize ()

## Detailed Description

Provides an easy to use C++ implementation of RSA's MD5 algorithm.

The default constructor is designed to provide much the same functionality as the most commonly used C-implementation, while the other three constructors are meant to further simplify the process of obtaining a digest by calculating the result in a single step.

KMD5 is state-based, that means you can add new contents with update() as long as you didn't request the digest value yet. After the digest value was requested, the object is "finalized" and you have to call reset() to be able to do another calculation with it. The reason for this behaviour is that upon requesting the message digest KMD5 has to pad the received contents up to a 64 byte boundary to calculate its value. After this operation it is not possible to resume consuming data.

### Usage:

A common usage of this class:

      const char* test1;
      KMD5::Digest rawResult;

      test1 = "This is a simple test.";
      KMD5 context (test1);
      cout << "Hex Digest output: " << context.hexDigest().data() << endl;

To cut down on the unnecessary overhead of creating multiple KMD5 objects, you can simply invoke reset() to reuse the same object in making another calculation:

      context.reset ();
      context.update ("TWO");
      context.update ("THREE");
      cout << "Hex Digest output: " << context.hexDigest().data() << endl;

typedef unsigned char Digest[16] | ### Digest[16]

KMD5 () | ### KMD5

KMD5 (const char* in, int len = -1) | ### KMD5

Constructor that updates the digest for the given string.

Parameters:

in | C string or binary data
len | if negative, calculates the length by using strlen on the first parameter, otherwise it trusts the given length (does not stop on NUL byte).

KMD5 (const QByteArray& a ) | ### KMD5

@overload

Same as above except it accepts a QByteArray as its argument.

KMD5 (const QCString& a ) | ### KMD5

@overload

Same as above except it accepts a QByteArray as its argument.

void update (const char* in, int len = -1) | ### update

Updates the message to be digested. Be sure to add all data before you read the digest. After reading the digest, you can not add more data!

Parameters:

in | message to be added to digest
len | the length of the given message.

void update (const unsigned char* in, int len = -1) | ### update

@overload

void update (const QByteArray& in ) | ### update

@overload

Parameters:

in | message to be added to the digest (QByteArray).

void update (const QCString& in ) | ### update

@overload

Parameters:

in | message to be added to the digest (QByteArray).

bool update (QIODevice& file) | ### update

@overload

reads the data from an I/O device, i.e. from a file (QFile).

NOTE that the file must be open for reading.

Parameters:

file | a pointer to FILE as returned by calls like f{d,re}open

Returns: false if an error occured during reading.

void reset () | ### reset

Calling this function will reset the calculated message digest. Use this method to perform another message digest calculation without recreating the KMD5 object.

const Digest& rawDigest () | ### rawDigest

Returns: the raw representation of the digest

void rawDigest ( KMD5::Digest& bin ) | ### rawDigest

Fills the given array with the binary representation of the message digest.

Use this method if you do not want to worry about making copy of the digest once you obtain it.

Parameters:

bin | an array of 16 characters ( char[16] )

QCString hexDigest () | ### hexDigest

Returns the value of the calculated message digest in a hexadecimal representation.

void hexDigest (QCString&) | ### hexDigest

@overload

QCString base64Digest () | ### base64Digest

Returns the value of the calculated message digest in a base64-encoded representation.

bool verify ( const KMD5::Digest& digest) | ### verify

returns true if the calculated digest for the given message matches the given one.

bool verify (const QCString&) | ### verify

@overload

void transform ( const unsigned char buffer[64] ) | ### transform

[protected]

Performs the real update work. Note that length is implied to be 64.

void finalize () | ### finalize

[protected]

finalizes the digest

- Author: Dirk Mueller , Dawit Alemayehu
- Generated: root on macppc.ports.openbsd.org on Sat Sep 6 10:36:15 2003, using kdoc 2.0a54.