source: box/trunk/lib/crypto/MD5Digest.cpp @ 217

Revision 217, 1.3 KB checked in by martin, 6 years ago (diff)

Set svn:eol-style as appropriate for all files

  • Property svn:eol-style set to native
Line 
1// --------------------------------------------------------------------------
2//
3// File
4//              Name:    MD5Digest.cpp
5//              Purpose: Simple interface for creating MD5 digests
6//              Created: 8/12/03
7//
8// --------------------------------------------------------------------------
9
10
11#include "Box.h"
12
13#include "MD5Digest.h"
14
15#include "MemLeakFindOn.h"
16
17
18MD5Digest::MD5Digest()
19{
20        MD5_Init(&md5);
21        for(unsigned int l = 0; l < sizeof(mDigest); ++l)
22        {
23                mDigest[l] = 0;
24        }
25}
26
27MD5Digest::~MD5Digest()
28{
29}
30
31void MD5Digest::Add(const std::string &rString)
32{
33        MD5_Update(&md5, rString.c_str(), rString.size());
34}
35
36void MD5Digest::Add(const void *pData, int Length)
37{
38        MD5_Update(&md5, pData, Length);
39}
40
41void MD5Digest::Finish()
42{
43        MD5_Final(mDigest, &md5);
44}
45
46std::string MD5Digest::DigestAsString()
47{
48        std::string r;
49
50        static const char *hex = "0123456789abcdef";
51
52        for(unsigned int l = 0; l < sizeof(mDigest); ++l)
53        {
54                r += hex[(mDigest[l] & 0xf0) >> 4];
55                r += hex[(mDigest[l] & 0x0f)];
56        }
57
58        return r;
59}
60
61int MD5Digest::CopyDigestTo(uint8_t *to)
62{
63        for(int l = 0; l < MD5_DIGEST_LENGTH; ++l)
64        {
65                to[l] = mDigest[l];
66        }
67
68        return MD5_DIGEST_LENGTH;
69}
70
71
72bool MD5Digest::DigestMatches(uint8_t *pCompareWith) const
73{
74        for(int l = 0; l < MD5_DIGEST_LENGTH; ++l)
75        {
76                if(pCompareWith[l] != mDigest[l])
77                        return false;
78        }
79
80        return true;
81}
82
Note: See TracBrowser for help on using the repository browser.