M
M
Maxim Barulin2014-06-15 13:22:33
OpenSSL
Maxim Barulin, 2014-06-15 13:22:33

C++, openssl how to make block encryption correct?

Good day,% habrauser%!
I am writing a simple fcgi application using openssl that will encrypt/decrypt incoming data. I don't know much about C++, so bicycle building is possible... Tell me how to properly encrypt / decrypt data in blocks? The code is here . In the previous version, it seemed to work, but crookedly due to the use of uninitialized variables. In the current one I'm trying to avoid this by block encryption, but it turns out nonsense of the form:

param_par: action=encrypt
param_par: text=my text for encrypt
substr size is 16
substr is my text for encr
substr encr is rH.gKf۵my text for encr
substr size is 3
substr is ypt
substr encr is :(ɬp9H,-ypt
final is rH.gKf۵my text for encr:(ɬp9H,-ypt:(ɬp9H,-ܫVD[g

As you can see, after encryption, the variable contains both the encrypted data and the original string. I don't understand how to win.
I would be grateful for any help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2014-06-15
@jcmvbkbc

//шифруем блок
if (1 != EVP_EncryptUpdate(ctx, out_buffer, &len, buffer, BUFF_SIZE))
handleErrors();

printf("substr encr is %s\n", (char *)out_buffer);
//запоминаем результат
e_param->result.append((char *) out_buffer);

index++;
e_param->data_len -= BUFF_SIZE;

You don't use len anywhere, which is returned to you by EVP_EncryptUpdate, and for some reason you think that out_buffer can be treated like a C-string (which is not true).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question