\section{KMD5 Class Reference}
\label{classKMD5}\index{KMD5@{KMD5}}
Provides an easy to use C++ implementation of RSA's MD5 algorithm. An adapted C++ implementation of RSA Data Securities MD5 algorithm.  


{\tt \#include $<$kmdcodec.h$>$}

\subsection*{Public Types}
\begin{CompactItemize}
\item 
typedef unsigned char {\bf Digest} [16]\label{classKMD5_w0}

\end{CompactItemize}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
{\bf KMD5} (const  char $\ast$in, int len=-1)
\begin{CompactList}\small\item\em Constructor that updates the digest for the given string. \item\end{CompactList}\item 
{\bf KMD5} (const  {\bf QByte\-Array} \&a)
\item 
{\bf KMD5} (const  {\bf QCString} \&a)
\item 
void {\bf update} (const  char $\ast$in, int len=-1)
\begin{CompactList}\small\item\em Updates the message to be digested. \item\end{CompactList}\item 
void {\bf update} (const  unsigned char $\ast$in, int len=-1)
\item 
void {\bf update} (const  {\bf QByte\-Array} \&in)
\item 
void {\bf update} (const  {\bf QCString} \&in)
\item 
bool {\bf update} ({\bf QIODevice} \&file)
\item 
void {\bf reset} ()
\begin{CompactList}\small\item\em Calling this function will reset the calculated message digest. \item\end{CompactList}\item 
const  Digest \& {\bf raw\-Digest} ()
\item 
void {\bf raw\-Digest} (KMD5::Digest \&bin)
\begin{CompactList}\small\item\em Fills the given array with the binary representation of the message digest. \item\end{CompactList}\item 
{\bf QCString} {\bf hex\-Digest} ()
\begin{CompactList}\small\item\em Returns the value of the calculated message digest in a hexadecimal representation. \item\end{CompactList}\item 
void {\bf hex\-Digest} ({\bf QCString} \&)
\item 
{\bf QCString} {\bf base64Digest} ()
\begin{CompactList}\small\item\em Returns the value of the calculated message digest in a base64-encoded representation. \item\end{CompactList}\item 
bool {\bf verify} (const  KMD5::Digest \&digest)
\begin{CompactList}\small\item\em returns true if the calculated digest for the given message matches the given one. \item\end{CompactList}\item 
bool {\bf verify} (const  {\bf QCString} \&)
\end{CompactItemize}
\subsection*{Protected Member Functions}
\begin{CompactItemize}
\item 
void {\bf transform} (const  unsigned char buffer[64])
\begin{CompactList}\small\item\em Performs the real update work. \item\end{CompactList}\item 
void {\bf finalize} ()
\begin{CompactList}\small\item\em finalizes the digest \item\end{CompactList}\end{CompactItemize}


\subsection{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 {\bf update()}{\rm (p.\,\pageref{classKMD5_a4})} as long as you didn't request the digest value yet. After the digest value was requested, the object is \char`\"{}finalized\char`\"{} and you have to call {\bf reset()}{\rm (p.\,\pageref{classKMD5_a9})} 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.

{\bf  Usage:}

{\bf  A common usage of this class:}

{\bf  \small\begin{alltt}
  const char* test1;
  KMD5::Digest rawResult;\end{alltt}\normalsize 
}

{\bf \small\begin{alltt}  test1 = "This is a simple test.";
  KMD5 context (test1);
  cout $<$$<$ "Hex Digest output: " $<$$<$ context.hexDigest().data() $<$$<$ endl;
 \end{alltt}\normalsize 
}

{\bf  To cut down on the unnecessary overhead of creating multiple KMD5 objects, you can simply invoke {\bf reset}{\rm (p.\,\pageref{classKMD5_a9})}() to reuse the same object in making another calculation:}

{\bf  \small\begin{alltt}
  context.reset ();
  context.update ("TWO");
  context.update ("THREE");
  cout $<$$<$ "Hex Digest output: " $<$$<$ context.hexDigest().data() $<$$<$ endl;
 \end{alltt}\normalsize 
}

{\bf }

{\bf \begin{Desc}
\item[Author:]Dirk Mueller $<${\tt mueller@kde.org}$>$, Dawit Alemayehu $<${\tt adawit@kde.org}$>$ \end{Desc}
}



Definition at line 404 of file kmdcodec.h.

\subsection{Constructor \& Destructor Documentation}
\index{KMD5@{KMD5}!KMD5@{KMD5}}
\index{KMD5@{KMD5}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KMD5::KMD5 (const char $\ast$ {\em in}, int {\em len} = -1)}\label{classKMD5_a1}


Constructor that updates the digest for the given string. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em in}]C string or binary data \item[{\em 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). \end{description}
\end{Desc}


Definition at line 752 of file kmdcodec.cpp.

References update().\index{KMD5@{KMD5}!KMD5@{KMD5}}
\index{KMD5@{KMD5}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KMD5::KMD5 (const {\bf QByte\-Array} \& {\em a})}\label{classKMD5_a2}


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 {\bf QByte\-Array} as its argument. 

Definition at line 758 of file kmdcodec.cpp.

References update().\index{KMD5@{KMD5}!KMD5@{KMD5}}
\index{KMD5@{KMD5}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KMD5::KMD5 (const {\bf QCString} \& {\em a})}\label{classKMD5_a3}


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 {\bf QByte\-Array} as its argument. 

Definition at line 764 of file kmdcodec.cpp.

References update().

\subsection{Member Function Documentation}
\index{KMD5@{KMD5}!update@{update}}
\index{update@{update}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KMD5::update (const char $\ast$ {\em in}, int {\em len} = -1)\hspace{0.3cm}{\tt  [inline]}}\label{classKMD5_a4}


Updates the message to be digested. 

Be sure to add all data before you read the digest. After reading the digest, you can {\bf not} add more data!

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em in}]message to be added to digest \item[{\em len}]the length of the given message. \end{description}
\end{Desc}


Definition at line 444 of file kmdcodec.h.

Referenced by finalize(), KMD5(), and update().\index{KMD5@{KMD5}!update@{update}}
\index{update@{update}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KMD5::update (const unsigned char $\ast$ {\em in}, int {\em len} = -1)}\label{classKMD5_a5}


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().\index{KMD5@{KMD5}!update@{update}}
\index{update@{update}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KMD5::update (const {\bf QByte\-Array} \& {\em in})}\label{classKMD5_a6}


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

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em in}]message to be added to the digest ({\bf QByte\-Array}). \end{description}
\end{Desc}


Definition at line 770 of file kmdcodec.cpp.

References update().\index{KMD5@{KMD5}!update@{update}}
\index{update@{update}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KMD5::update (const {\bf QCString} \& {\em in})}\label{classKMD5_a7}


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

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em in}]message to be added to the digest ({\bf QByte\-Array}). \end{description}
\end{Desc}


Definition at line 775 of file kmdcodec.cpp.

References QCString::length(), and update().\index{KMD5@{KMD5}!update@{update}}
\index{update@{update}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KMD5::update ({\bf QIODevice} \& {\em file})}\label{classKMD5_a8}


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 ({\bf QFile}).

NOTE that the file must be open for reading.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em file}]a pointer to FILE as returned by calls like f\{d,re\}open\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]false if an error occured during reading. \end{Desc}


Definition at line 823 of file kmdcodec.cpp.

References QIODevice::at\-End(), QIODevice::read\-Block(), and update().\index{KMD5@{KMD5}!reset@{reset}}
\index{reset@{reset}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KMD5::reset ()}\label{classKMD5_a9}


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.\index{KMD5@{KMD5}!rawDigest@{rawDigest}}
\index{rawDigest@{rawDigest}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}const  KMD5::Digest \& KMD5::raw\-Digest ()}\label{classKMD5_a10}


\begin{Desc}
\item[Returns:]the raw representation of the digest \end{Desc}


Definition at line 882 of file kmdcodec.cpp.

References finalize().

Referenced by verify().\index{KMD5@{KMD5}!rawDigest@{rawDigest}}
\index{rawDigest@{rawDigest}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KMD5::raw\-Digest (KMD5::Digest \& {\em bin})}\label{classKMD5_a11}


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.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em bin}]an array of 16 characters ( char[16] ) \end{description}
\end{Desc}


Definition at line 888 of file kmdcodec.cpp.

References finalize().\index{KMD5@{KMD5}!hexDigest@{hexDigest}}
\index{hexDigest@{hexDigest}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QCString} KMD5::hex\-Digest ()}\label{classKMD5_a12}


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().\index{KMD5@{KMD5}!hexDigest@{hexDigest}}
\index{hexDigest@{hexDigest}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KMD5::hex\-Digest ({\bf QCString} \&)}\label{classKMD5_a13}


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().\index{KMD5@{KMD5}!base64Digest@{base64Digest}}
\index{base64Digest@{base64Digest}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QCString} KMD5::base64Digest ()}\label{classKMD5_a14}


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().\index{KMD5@{KMD5}!verify@{verify}}
\index{verify@{verify}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KMD5::verify (const KMD5::Digest \& {\em digest})}\label{classKMD5_a15}


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 raw\-Digest().\index{KMD5@{KMD5}!verify@{verify}}
\index{verify@{verify}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KMD5::verify (const {\bf QCString} \&)}\label{classKMD5_a16}


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 hex\-Digest().\index{KMD5@{KMD5}!transform@{transform}}
\index{transform@{transform}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KMD5::transform (const unsigned char {\em buffer}[64])\hspace{0.3cm}{\tt  [protected]}}\label{classKMD5_b0}


Performs the real update work. 

Note that length is implied to be 64. 

Definition at line 950 of file kmdcodec.cpp.

Referenced by update().\index{KMD5@{KMD5}!finalize@{finalize}}
\index{finalize@{finalize}!KMD5@{KMD5}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KMD5::finalize ()\hspace{0.3cm}{\tt  [protected]}}\label{classKMD5_b1}


finalizes the digest 



Definition at line 834 of file kmdcodec.cpp.

References update().

Referenced by base64Digest(), hex\-Digest(), raw\-Digest(), and verify().

The documentation for this class was generated from the following files:\begin{CompactItemize}
\item 
kmdcodec.h\item 
kmdcodec.cpp\end{CompactItemize}
