kdecore Library API Documentation

KMD5 Class Reference

Provides an easy to use C++ implementation of RSA's MD5 algorithm. An adapted C++ implementation of RSA Data Securities MD5 algorithm. More...

#include <kmdcodec.h>

List of all members.

Public Types

typedef unsigned char Digest [16]

Public Member Functions

 KMD5 (const char *in, int len=-1)
 Constructor that updates the digest for the given string.

 KMD5 (const QByteArray &a)
 KMD5 (const QCString &a)
void update (const char *in, int len=-1)
 Updates the message to be digested.

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 ()
 Calling this function will reset the calculated message digest.

const Digest & rawDigest ()
void rawDigest (KMD5::Digest &bin)
 Fills the given array with the binary representation of the message digest.

QCString hexDigest ()
 Returns the value of the calculated message digest in a hexadecimal representation.

void hexDigest (QCString &)
QCString base64Digest ()
 Returns the value of the calculated message digest in a base64-encoded representation.

bool verify (const KMD5::Digest &digest)
 returns true if the calculated digest for the given message matches the given one.

bool verify (const QCString &)

Protected Member Functions

void transform (const unsigned char buffer[64])
 Performs the real update work.

void finalize ()
 finalizes the digest


Detailed Description

Provides an easy to use C++ implementation of RSA's MD5 algorithm. An adapted C++ implementation of RSA Data Securities 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;

Author:
Dirk Mueller <mueller@kde.org>, Dawit Alemayehu <adawit@kde.org>

Definition at line 404 of file kmdcodec.h.


Constructor & Destructor Documentation

KMD5::KMD5 const char *  in,
int  len = -1
 

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).

Definition at line 752 of file kmdcodec.cpp.

References update().

KMD5::KMD5 const QByteArray a  ) 
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Definition at line 758 of file kmdcodec.cpp.

References update().

KMD5::KMD5 const QCString a  ) 
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Definition at line 764 of file kmdcodec.cpp.

References update().


Member Function Documentation

void KMD5::update const char *  in,
int  len = -1
[inline]
 

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.

Definition at line 444 of file kmdcodec.h.

Referenced by finalize(), KMD5(), and update().

void KMD5::update const unsigned char *  in,
int  len = -1
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 780 of file kmdcodec.cpp.

References transform().

void KMD5::update const QByteArray in  ) 
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
in message to be added to the digest (QByteArray).

Definition at line 770 of file kmdcodec.cpp.

References update().

void KMD5::update const QCString in  ) 
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
in message to be added to the digest (QByteArray).

Definition at line 775 of file kmdcodec.cpp.

References QCString::length(), and update().

bool KMD5::update QIODevice file  ) 
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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.

Definition at line 823 of file kmdcodec.cpp.

References QIODevice::atEnd(), QIODevice::readBlock(), and update().

void KMD5::reset  ) 
 

Calling this function will reset the calculated message digest.

Use this method to perform another message digest calculation without recreating the KMD5 object.

Definition at line 934 of file kmdcodec.cpp.

const KMD5::Digest & KMD5::rawDigest  ) 
 

Returns:
the raw representation of the digest

Definition at line 882 of file kmdcodec.cpp.

References finalize().

Referenced by verify().

void KMD5::rawDigest KMD5::Digest &  bin  ) 
 

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] )

Definition at line 888 of file kmdcodec.cpp.

References finalize().

QCString KMD5::hexDigest  ) 
 

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

Definition at line 895 of file kmdcodec.cpp.

References finalize().

Referenced by verify().

void KMD5::hexDigest QCString  ) 
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 908 of file kmdcodec.cpp.

References finalize(), and QCString::resize().

QCString KMD5::base64Digest  ) 
 

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

Definition at line 918 of file kmdcodec.cpp.

References KCodecs::base64Encode(), and finalize().

bool KMD5::verify const KMD5::Digest &  digest  ) 
 

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

Definition at line 870 of file kmdcodec.cpp.

References finalize(), and rawDigest().

bool KMD5::verify const QCString  ) 
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 876 of file kmdcodec.cpp.

References finalize(), and hexDigest().

void KMD5::transform const unsigned char  buffer[64]  )  [protected]
 

Performs the real update work.

Note that length is implied to be 64.

Definition at line 950 of file kmdcodec.cpp.

Referenced by update().

void KMD5::finalize  )  [protected]
 

finalizes the digest

Definition at line 834 of file kmdcodec.cpp.

References update().

Referenced by base64Digest(), hexDigest(), rawDigest(), and verify().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:49:51 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001