Skip to content

Instantly share code, notes, and snippets.

@xnyhps
Created May 21, 2011 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnyhps/984568 to your computer and use it in GitHub Desktop.
Save xnyhps/984568 to your computer and use it in GitHub Desktop.
#include <cipher.h>
#include <stdio.h>
int main()
{
purple_ciphers_init();
char key[] = "Jefe";
char str[] = "what do ya want for nothing?";
char *hash = (char *)malloc(100 * sizeof(char));
memset(hash, 0, 100);
PurpleCipherContext *hmac;
hmac = purple_cipher_context_new_by_name("hmac", NULL);
purple_cipher_context_set_option(hmac, "hash", "sha1");
purple_cipher_context_set_key_with_len(hmac, (guchar *)key, strlen(key));
purple_cipher_context_append(hmac, str, strlen(str));
purple_cipher_context_digest_to_str(hmac, 100, hash, NULL);
purple_cipher_context_destroy(hmac);
printf("%s\n", hash);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment