Hi Adam,
A MAC is a keyed digest. It does not offer confidentiality - only
authentication.
Jeff
#include "sha.h"
using CryptoPP::SHA1;
#include "hmac.h"
using CryptoPP::HMAC;
#include <string>
using std::string;
int main(int argc, char* argv[])
{
byte key [ HMAC<SHA1>::DIGESTSIZE ];
byte digest [ HMAC<SHA1>::DIGESTSIZE ];
memset( key, 0, sizeof(key) );
HMAC<SHA1> hmac( key, sizeof(key ) );
string plain = "Hello World", mac;
hmac.Update( (byte*)plain.c_str(), plain.size() );
hmac.Final( digest );
// Wrap in a string for convenience
mac = string( (char*)digest, sizeof(digest ) );
/* ======================================== *\
\* ======================================== */
HMAC<SHA1> verifier( key, sizeof(key) );
bool b = false;
// b: true
b = verifier.VerifyDigest( digest,
(byte*)plain.c_str(), plain.size() );
// b: true
verifier.Restart();
b = verifier.VerifyDigest( (byte*)mac.c_str(),
(byte*)plain.c_str(), plain.size() );
// b: false
verifier.Restart();
plain = "hello world";
b = verifier.VerifyDigest( (byte*)mac.c_str(),
(byte*)plain.c_str(), plain.size() );
return 0;
}
On Mon, Jun 9, 2008 at 5:57 PM, Adam Harding <[EMAIL PROTECTED]> wrote:
>
> Thanks for reply.
>
> I have been looking at the HMAC-SHA test function in .cpp. But how do
> I go about actually using this piece of code to compute and then print
> a digest? Cant seem to figure it out.
>
> Many thanks.
>
> [SNIP]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [EMAIL PROTECTED]
More information about Crypto++ and this group is available at
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---