Hi, all.

Have anyone ever implemented strings encrypting with libmcrypt?
Especially, interested in MCRYPT_RIJNDAEL_256 with MCRYPT_OFB mode.

Tried to implement following the example from docs, but always gaining segmentation fault. Seems to me, that i missed something with iv size and block buffer size.

Would be happy, if somebody provide piece of code.

sorry, it doesn't work like that here.... espeically considering you're using a non-standard library.

you're going to have to post your code so we can replicate your failure, then maybe someone can diagnose why you're having a fault.

Sorry about that. Here's sample from my code:

#include <assert.h>
#include <mcrypt.h>
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

MCRYPT td;
char *IV;
int keysize = 32; /* 256 bits */


int main() {

	char *key, *hash;
	char *encrypted;
	int data_size, max_key_size, iv_size;

	key = "uLeeCo6riemoJoyaip5ohvaeniesoo2h";
	IV = "vdsfsdadfgshuobzuLeeCo6riemoJoya";

	hash = "a1i2tn9w5z7m";
	encrypted = (char *) malloc(sizeof(char));
	encrypted = strdup(hash);
	td = mcrypt_module_open(MCRYPT_RIJNDAEL_256, NULL, MCRYPT_OFB, NULL);
	keysize = strlen(key);

	mcrypt_generic_init(td, key, keysize, IV);

	mcrypt_generic(td, encrypted, data_size);
	fprintf(stderr, "Debug: secret: %s\n", encrypted);
	mdecrypt_generic(td, encrypted, data_size);
	fprintf(stderr, "Debug: unsecret: %s\n", encrypted);
	mcrypt_generic_deinit(td);
	mcrypt_module_close(td);
	return 0;
}

Encrypted and decrypted values doesn't match. compile string:

gcc -Wall -lmcrypt test.c -o test

And don't mention unused variables.

Maybe i shouldn't use MCRYPT_RIJNDAEL_256 and such mode?
Then, please, tell me if you know fast encrypting algorithm. It's not very important data, but nobody should decrypt it without knowing the key.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.