Example #1
0
static gchar   *twitter_oauth_sign(const gchar * txt, const gchar * key)
{
    PurpleCipher   *cipher;
    PurpleCipherContext *ctx;
    static guchar   output[20];
    size_t          output_size;

    cipher = purple_ciphers_find_cipher("hmac");
    if (!cipher) {
        purple_debug_error(GENERIC_PROTOCOL_ID, "%s: Could not find cipher\n", G_STRFUNC);
        return NULL;
    }
    ctx = purple_cipher_context_new(cipher, NULL);
    if (!ctx) {
        purple_debug_error(GENERIC_PROTOCOL_ID, "%s: Could not create cipher context\n", G_STRFUNC);
        return NULL;
    }
    purple_cipher_context_set_option(ctx, "hash", "sha1");

    purple_cipher_context_set_key(ctx, (guchar *) key);
    purple_cipher_context_append(ctx, (guchar *) txt, strlen(txt));
    if (!purple_cipher_context_digest(ctx, 20, output, &output_size)) {
        purple_debug_error(GENERIC_PROTOCOL_ID, "%s: Could not sign text\n", G_STRFUNC);
        purple_cipher_context_destroy(ctx);
        return NULL;
    }
    purple_cipher_context_destroy(ctx);
    return purple_base64_encode(output, output_size);

}
Example #2
0
/**
 * @return A null-terminated base64 encoded version of the HMAC
 *         calculated using the given key and data.
 */
static gchar *hmac_sha256(const char *key, const char *message)
{
    PurpleCipherContext *context;
    guchar digest[32];

    context = purple_cipher_context_new_by_name("hmac", NULL);
    purple_cipher_context_set_option(context, "hash", "sha256");
    purple_cipher_context_set_key(context, (guchar *)key);
    purple_cipher_context_append(context, (guchar *)message, strlen(message));
    purple_cipher_context_digest(context, sizeof(digest), digest, NULL);
    purple_cipher_context_destroy(context);

    return purple_base64_encode(digest, sizeof(digest));
}
Example #3
0
static char *
des3_cbc(const char *key, const char *iv, const char *data, int len, gboolean decrypt)
{
	PurpleCipherContext *des3;
	char *out;
	size_t outlen;

	des3 = purple_cipher_context_new_by_name("des3", NULL);
	purple_cipher_context_set_key(des3, (guchar *)key);
	purple_cipher_context_set_batch_mode(des3, PURPLE_CIPHER_BATCH_MODE_CBC);
	purple_cipher_context_set_iv(des3, (guchar *)iv, 8);

	out = g_malloc(len);
	if (decrypt)
		purple_cipher_context_decrypt(des3, (guchar *)data, len, (guchar *)out, &outlen);
	else
		purple_cipher_context_encrypt(des3, (guchar *)data, len, (guchar *)out, &outlen);

	purple_cipher_context_destroy(des3);

	return out;
}