#include <qmdcodec.h>
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.
QMD5 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 QMD5 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.
const char* test1; QMD5::Digest rawResult;
test1 = "This is a simple test."; QMD5 context (test1); cout << "Hex Digest output: " << context.hexDigest().data() << endl;
To cut down on the unnecessary overhead of creating multiple QMD5 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;
An adapted C++ implementation of RSA Data Securities MD5 algorithm.
Definition at line 406 of file qmdcodec.h.
Public Types | |
| typedef unsigned char | Digest [16] |
Public Member Functions | |
| QMD5 () | |
| QMD5 (const char *in, int len=-1) | |
| Constructor that updates the digest for the given string. | |
| QMD5 (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. | |
| QMD5 (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. | |
| void | update (const char *in, int len=-1) |
| Updates the message to be digested. | |
| void | 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. | |
| void | 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. | |
| void | 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. | |
| bool | 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. | |
| void | reset () |
| Calling this function will reset the calculated message digest. | |
| const Digest & | rawDigest () |
| void | rawDigest (QMD5::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 &) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| QCString | base64Digest () |
| Returns the value of the calculated message digest in a base64-encoded representation. | |
| bool | verify (const QMD5::Digest &digest) |
| returns true if the calculated digest for the given message matches the given one. | |
| bool | 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. | |
Protected Member Functions | |
| void | transform (const unsigned char buffer[64]) |
| Performs the real update work. | |
| void | finalize () |
| finalizes the digest | |
Private Member Functions | |
| QMD5 (const QMD5 &u) | |
| QMD5 & | operator= (const QMD5 &md) |
| void | init () |
| void | encode (unsigned char *output, Q_UINT32 *in, Q_UINT32 len) |
| void | decode (Q_UINT32 *output, const unsigned char *in, Q_UINT32 len) |
| Q_UINT32 | rotate_left (Q_UINT32 x, Q_UINT32 n) |
| Q_UINT32 | F (Q_UINT32 x, Q_UINT32 y, Q_UINT32 z) |
| Q_UINT32 | G (Q_UINT32 x, Q_UINT32 y, Q_UINT32 z) |
| Q_UINT32 | H (Q_UINT32 x, Q_UINT32 y, Q_UINT32 z) |
| Q_UINT32 | I (Q_UINT32 x, Q_UINT32 y, Q_UINT32 z) |
| void | FF (Q_UINT32 &a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, Q_UINT32 s, Q_UINT32 ac) |
| void | GG (Q_UINT32 &a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, Q_UINT32 s, Q_UINT32 ac) |
| void | HH (Q_UINT32 &a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, Q_UINT32 s, Q_UINT32 ac) |
| void | II (Q_UINT32 &a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, Q_UINT32 s, Q_UINT32 ac) |
Private Attributes | |
| Q_UINT32 | m_state [4] |
| Q_UINT32 | m_count [2] |
| Q_UINT8 | m_buffer [64] |
| Digest | m_digest |
| bool | m_finalized |
| QMD5Private * | d |
| typedef unsigned char QMD5::Digest[16] |
Definition at line 410 of file qmdcodec.h.
| QMD5::QMD5 | ( | ) |
Definition at line 757 of file qmdcodec.cpp.
| QMD5::QMD5 | ( | const char * | in, | |
| int | len = -1 | |||
| ) |
Constructor that updates the digest for the given string.
| 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 762 of file qmdcodec.cpp.
| QMD5::QMD5 | ( | 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 768 of file qmdcodec.cpp.
| QMD5::QMD5 | ( | 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 774 of file qmdcodec.cpp.
| QMD5::QMD5 | ( | const QMD5 & | u | ) | [private] |
| void QMD5::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!
| in | message to be added to digest | |
| len | the length of the given message. |
Definition at line 446 of file qmdcodec.h.
Referenced by HttpComms::calculateDigestResponse(), finalize(), QMD5(), and update().
| void QMD5::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 790 of file qmdcodec.cpp.
| void QMD5::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.
| in | message to be added to the digest (QByteArray). |
Definition at line 780 of file qmdcodec.cpp.
| void QMD5::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.
| in | message to be added to the digest (QByteArray). |
Definition at line 785 of file qmdcodec.cpp.
| bool QMD5::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.
| file | a pointer to FILE as returned by calls like f{d,re}open |
Definition at line 833 of file qmdcodec.cpp.
| void QMD5::reset | ( | ) |
Calling this function will reset the calculated message digest.
Use this method to perform another message digest calculation without recreating the QMD5 object.
Definition at line 944 of file qmdcodec.cpp.
Referenced by HttpComms::calculateDigestResponse(), and init().
| const QMD5::Digest & QMD5::rawDigest | ( | ) |
Definition at line 892 of file qmdcodec.cpp.
Referenced by verify().
| void QMD5::rawDigest | ( | QMD5::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.
| bin | an array of 16 characters ( char[16] ) |
Definition at line 898 of file qmdcodec.cpp.
| QCString QMD5::hexDigest | ( | ) |
Returns the value of the calculated message digest in a hexadecimal representation.
Definition at line 905 of file qmdcodec.cpp.
Referenced by HttpComms::calculateDigestResponse(), and verify().
| void QMD5::hexDigest | ( | QCString & | s | ) |
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 918 of file qmdcodec.cpp.
| QCString QMD5::base64Digest | ( | ) |
Returns the value of the calculated message digest in a base64-encoded representation.
Definition at line 928 of file qmdcodec.cpp.
| bool QMD5::verify | ( | const QMD5::Digest & | digest | ) |
returns true if the calculated digest for the given message matches the given one.
Definition at line 880 of file qmdcodec.cpp.
| bool QMD5::verify | ( | const QCString & | hexdigest | ) |
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 886 of file qmdcodec.cpp.
| void QMD5::transform | ( | const unsigned char | buffer[64] | ) | [protected] |
Performs the real update work.
Note that length is implied to be 64.
Definition at line 960 of file qmdcodec.cpp.
Referenced by update().
| void QMD5::finalize | ( | ) | [protected] |
finalizes the digest
Definition at line 844 of file qmdcodec.cpp.
Referenced by base64Digest(), hexDigest(), rawDigest(), and verify().
| void QMD5::init | ( | ) | [private] |
| void QMD5::encode | ( | unsigned char * | output, | |
| Q_UINT32 * | in, | |||
| Q_UINT32 | len | |||
| ) | [private] |
| void QMD5::decode | ( | Q_UINT32 * | output, | |
| const unsigned char * | in, | |||
| Q_UINT32 | len | |||
| ) | [private] |
| Q_UINT32 QMD5::rotate_left | ( | Q_UINT32 | x, | |
| Q_UINT32 | n | |||
| ) | [inline, private] |
| Q_UINT32 QMD5::F | ( | Q_UINT32 | x, | |
| Q_UINT32 | y, | |||
| Q_UINT32 | z | |||
| ) | [inline, private] |
| Q_UINT32 QMD5::G | ( | Q_UINT32 | x, | |
| Q_UINT32 | y, | |||
| Q_UINT32 | z | |||
| ) | [inline, private] |
| Q_UINT32 QMD5::H | ( | Q_UINT32 | x, | |
| Q_UINT32 | y, | |||
| Q_UINT32 | z | |||
| ) | [inline, private] |
| Q_UINT32 QMD5::I | ( | Q_UINT32 | x, | |
| Q_UINT32 | y, | |||
| Q_UINT32 | z | |||
| ) | [inline, private] |
| void QMD5::FF | ( | Q_UINT32 & | a, | |
| Q_UINT32 | b, | |||
| Q_UINT32 | c, | |||
| Q_UINT32 | d, | |||
| Q_UINT32 | x, | |||
| Q_UINT32 | s, | |||
| Q_UINT32 | ac | |||
| ) | [private] |
| void QMD5::GG | ( | Q_UINT32 & | a, | |
| Q_UINT32 | b, | |||
| Q_UINT32 | c, | |||
| Q_UINT32 | d, | |||
| Q_UINT32 | x, | |||
| Q_UINT32 | s, | |||
| Q_UINT32 | ac | |||
| ) | [private] |
| void QMD5::HH | ( | Q_UINT32 & | a, | |
| Q_UINT32 | b, | |||
| Q_UINT32 | c, | |||
| Q_UINT32 | d, | |||
| Q_UINT32 | x, | |||
| Q_UINT32 | s, | |||
| Q_UINT32 | ac | |||
| ) | [private] |
| void QMD5::II | ( | Q_UINT32 & | a, | |
| Q_UINT32 | b, | |||
| Q_UINT32 | c, | |||
| Q_UINT32 | d, | |||
| Q_UINT32 | x, | |||
| Q_UINT32 | s, | |||
| Q_UINT32 | ac | |||
| ) | [private] |
Q_UINT32 QMD5::m_state[4] [private] |
Q_UINT32 QMD5::m_count[2] [private] |
Q_UINT8 QMD5::m_buffer[64] [private] |
Digest QMD5::m_digest [private] |
Definition at line 569 of file qmdcodec.h.
Referenced by base64Digest(), finalize(), hexDigest(), rawDigest(), and reset().
bool QMD5::m_finalized [private] |
Definition at line 570 of file qmdcodec.h.
Referenced by finalize(), reset(), transform(), and update().
QMD5Private* QMD5::d [private] |
1.5.5