M
M
Maxim Barulin2014-05-29 10:00:19
OpenSSL
Maxim Barulin, 2014-05-29 10:00:19

C++, openssl, fcgi what's wrong with the decrypt function?

Good day,% habrauser% Tell me
, why does it show the correct phrase in the console when decrypting previously encrypted text, and a lot of rubbish comes into the stream? Example,

console output
Lib is inited                                                                                                                                             
Socket is opened
Request is inited
Try to accept new request
request is accepted
param_par: action=encrypt
param_par: text=my text for encrypt
Encr text is: [email protected]]P֦Ǒf
data len: 19
chph_len: 32
hash_len: 45
Hash text is: TS52kR7EQPq0HlaUcjW2QV2051DA1qb0x5ERmpyY/2b/

Try to accept new request
request is accepted
param_par: action=decrypt
param_par: text=TS52kR7EQPq0HlaUcjW2QV2051DA1qb0x5ERmpyY/2b/
hash_len len: 44
chph len: 33
chph is: [email protected]]P֦Ǒf
result_len: 64
inal: my text for encrypt
response in browser
string(235) "HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Date: Thu, 29 May 2014 06:54:40 GMT
Server: Apache/2.4.9 (Win32) PHP/5.5.11
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

TS52kR7EQPq0HlaUcjW2QV2051DA1qb0x5ERmpyY/2b/
"
string(223) "HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Date: Thu, 29 May 2014 06:54:43 GMT
Server: Apache/2.4.9 (Win32) PHP/5.5.11
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

my text for encrypt












я"


As far as I can guess, the problem here lies somewhere around the EVP_DecryptFinal_ex function, which, when called, shows the following error:
2147144708:error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length:evp_enc.c:532:

I will be grateful for any help.
Sources on github https://github.com/Slavenin/fcgi_encrypt

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Barulin, 2014-05-29
@Slavenin999

Problem solved. It was necessary to simply reduce the size of the text decoded in 64 by 1 (as I understand it, 0 bytes)

J
jcmvbkbc, 2014-05-29
@jcmvbkbc

e_param.text = (unsigned char *) data->c_str();
...
e_param->text[e_param->data_len] = '\0';
std::string::c_str returns const char *, this string cannot be modified.
e_param->result is not initialized by now

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question