Hi all,
I have a problem using EVP interface .

This is my routine to encrypt data:

int encrypt(EVP_CIPHER_CTX *x, char * in, char * buf_out )
{

    int text_len;
    int loutU;
    int loutF;


    text_len = strlen(in) + 1; // i.e : adding '\0'

    if( EVP_EncryptUpdate(x, (unsigned char *)buf_out, &loutU, ( unsigned 
char*) in, text_len) == 0 )
        return -1;

    if( EVP_EncryptFinal_ex(x, (unsigned char *) &buf_out[loutU], &loutF) == 0 )
        return -1;    

    return loutU + loutF;
}
        

And this to decrypt:

int decrypt(char* in, EVP_CIPHER_CTX * x, int size_cipher_text, char * 
buffer_decrypted)
{
    int loutU;
    int loutF;
  
    if( EVP_DecryptUpdate(x, (unsigned char *)(buffer_decrypted), 
&loutU,(unsigned char *) in, size_cipher_text) ==0 )
        return -1;
    if( EVP_DecryptFinal_ex(x, (unsigned char *) (&buffer_decrypted[loutU]), 
&loutF) == 0 )
        return -1;

    bzero(in, size_cipher_text);    
    return loutU + loutF;
    

}

Client send to Server encrypt data, first time all works fine, but second time 
no.
For example if I first time send:
"Stack Overflow" server print "Stack Overflow",
but second time anything client sends, server always print "erflow".
Note that erflow is part of 2-nd byte of first message.

Can you help me?

Thanks

Enrico 
                                          

Reply via email to