]> git.tdb.fi Git - libs/crypto.git/blob - source/hash.cpp
Add an example program demonstrating hash API
[libs/crypto.git] / source / hash.cpp
1 #include <vector>
2 #include "hash.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace Crypto {
8
9 void Hash::update(const string &str)
10 {
11         update(str.data(), str.size());
12 }
13
14 string Hash::get_hexdigest() const
15 {
16         static const char hexdigits[] = "0123456789abcdef";
17
18         vector<char> digest(get_digest_size());
19         unsigned len = get_digest(&digest[0], digest.size());
20         string hex(len*2, '0');
21         for(unsigned i=0; i<len; ++i)
22         {
23                 hex[i*2] = hexdigits[(digest[i]>>4)&15];
24                 hex[i*2+1] = hexdigits[digest[i]&15];
25         }
26         return hex;
27 }
28
29 } // namespace Crypto
30 } // namespace Msp