\section{KMD5 Class Reference}
\label{classKMD5}\index{KMD5@{KMD5}}
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)
\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)
\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} ()
\item 
const Digest \& {\bf raw\-Digest} ()
\item 
void {\bf raw\-Digest} (KMD5::Digest \&bin)
\item 
{\bf QCString} {\bf hex\-Digest} ()
\item 
void {\bf hex\-Digest} ({\bf QCString} \&)
\item 
{\bf QCString} {\bf base64Digest} ()
\item 
bool {\bf verify} (const KMD5::Digest \&digest)
\item 
bool {\bf verify} (const {\bf QCString} \&)
\end{CompactItemize}
\subsection*{Protected Member Functions}
\begin{CompactItemize}
\item 
void {\bf transform} (const unsigned char buffer[64])
\item 
void {\bf finalize} ()
\end{CompactItemize}


\subsection{Detailed Description}
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 behavior 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:} 

A common usage of this class:



\footnotesize\begin{verbatim} const char* test1;
 KMD5::Digest rawResult;

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


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:



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


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




Definition at line 402 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} = {\tt -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 756 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 762 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 QCString} as its argument. 

Definition at line 768 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} = {\tt -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 442 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} = {\tt -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 784 of file kmdcodec.cpp.

References endl(), and 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 774 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 QCString}). \end{description}
\end{Desc}


Definition at line 779 of file kmdcodec.cpp.

References 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 occurred during reading. \end{Desc}


Definition at line 827 of file kmdcodec.cpp.

References 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 938 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 886 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 892 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 899 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 912 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 922 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 874 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 880 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 954 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 838 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}
