A simple CyaSSL-based HMAC-MD5 implementation. Licensed under GPL v2.
Dependents: RFrec_full RFtrans_full
The output will be base64-encoded, with trailing "==", like this:
j62o/jZsAZD9i9m+32lIuQ==
Example
#include "mbed.h" #include "hmac_md5.h" Serial pc(USBTX, USBRX); // tx, rx void main(void) { const char * key = "MySecretKey"; const char * text = "message to be signed"; char output[26]; HMAC_MD5(key, text, output); printf("result = %s\n", output); while(true){} }
Diff: hmac_md5.cpp
- Revision:
- 0:83f3dcfa5c8f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hmac_md5.cpp Wed Feb 06 20:35:03 2013 +0000 @@ -0,0 +1,19 @@ +#include "hmac_md5.h" +#include "hmac.h" +#include "coding.h" + +void HMAC_MD5(const char * szKey, const char * szText, char * szOutput) +{ + Hmac hmac; + char hmacOutput[MD5_DIGEST_SIZE + 1]; + + HmacSetKey(&hmac, MD5, (const byte *) szKey, strlen(szKey)); + HmacUpdate(&hmac, (const byte *) szText, strlen(szText)); + + HmacFinal(&hmac, (byte *) hmacOutput); + + int encodedLength = 25; + Base64_Encode((const byte *) hmacOutput, MD5_DIGEST_SIZE, (byte *) szOutput, (word32*) &encodedLength); + szOutput[encodedLength] = 0; + +}