How to create a HMAC 256 using the Crypto++ library?
<p>I have a string which I need to encode in HMAC 256 using C++ and Crypto++. The code from the library <a href="https://www.cryptopp.com/wiki/HMAC" rel="nofollow">wiki</a>:</p>

<pre><code>AutoSeededRandomPool prng;
SecByteBlock key(16);
prng.GenerateBlock(key, key.size());

string plain = "HMAC Test";
string mac, encoded;

/*********************************\
\*********************************/

// Pretty print key
encoded.clear();
StringSource ss1(key, key.size(), true,
    new HexEncoder(
        new StringSink(encoded)
    ) // HexEncoder
); // StringSource

cout &lt;&lt; "key: " &lt;&lt; encoded &lt;&lt; endl;
cout &lt;&lt; "plain text: " &lt;&lt; plain &lt;&lt; endl;

/*********************************\
\*********************************/

try
{
    HMAC&lt; SHA256 &gt; hmac(key, key.size());

    StringSource ss2(plain, true, 
        new HashFilter(hmac,
            new StringSink(mac)
        ) // HashFilter      
    ); // StringSource
}
catch(const CryptoPP::Exception&amp; e)
{
    cerr &lt;&lt; e.what() &lt;&lt; endl;
    exit(1);
}

/*********************************\
\*********************************/

// Pretty print
encoded.clear();
StringSource ss3(mac, true,
    new HexEncoder(
        new StringSink(encoded)
    ) // HexEncoder
); // StringSource

cout &lt;&lt; "hmac: " &lt;&lt; encoded &lt;&lt; endl;
</code></pre>

<p>The example provide works, but seems to do a hell of a lot. All I am trying to do is:</p>

<ol>
<li>Take a string: "GreatWallOfChina"</li>
<li>key: m2hspk1ZxsjlsDU6JhMvD3TQQhm+zOwab3slKEILoSSnfk3b2+NUyeJiCrRAJ/D3V5y+QDZaIqRx9q9siMopaA==</li>
<li>Convert key to base64: bTJoc3BrMVp4c2psc0RVNkpoTXZEM1RRUWhtK3pPd2FiM3NsS0VJTG9TU25mazNiMitOVXllSmlDclJBSi9EM1Y1eStRRFphSXFSeDlxOXNpTW9wYUE9PQ==</li>
<li>Using that base64 key to create a hmac256.</li>
</ol>

<p>So, my question is, are all the steps in the example code above necessary? (Byte block declarations, Hex encoding etc)</p>

<p>Apologies if this is a very noobish question.</p>