Thank you for your quick answer!
I see what you mean... that's the problem: How can I guarantee this?? I
will receive an encrypted data, I have the key and the vector. How can I
decrypted the data ??
Thanks!
On Mon, May 19, 2008 at 4:53 PM, Michael S. Zick <[EMAIL PROTECTED]>
wrote:
> On Mon May 19 2008 09:35, karim Bendadda wrote:
> > *Sorry for the first mail!!*
> >
>
> Unless you can guarantee that the strings do not contain embedded zeros;
> strlen() will not give the expected results.
>
> Mike
> > Hi all,
> >
> > I'm new on openssl development, so I'm sorry if that a "beginner's"
> > question . I'm trying to decrypt a *base64 AES CBC* encrypted data (using
> > the *AES_cbc_encrypt*). The base64 encoding/decoding works fine. the code
> > below works depending on data length:
> >
> > - The example with :
> >
> >
> > data ="*This is a long very long test*" works fine, I have the good
> > decrypted data.
> >
> > - The second one "*This is a test*" doesn't work... I read somewhere
> > that's depending of data padding... Have you any idea??
> >
> >
> > ......
> > int main(int argc, char *argv[])
> > {
> > unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e'};
> > unsigned char iv[] = {0,1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e'};
> > unsigned char iv1[] = {0,1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e'};
> >
> >
> >
> > unsigned char* data ="This is a test";
> > //unsigned char* data ="This is a long very long test";
> >
> > unsigned char* buffer = (char *) malloc(60);
> > unsigned char* buffer1 = (char *) malloc(60);
> >
> >
> > unsigned long bufferLength= (ceil(strlen(data)/16)+1)*16;
> >
> > AES_KEY aeskeyEnc, aeskeyDec;
> >
> >
> > AES_set_encrypt_key (key, KeyLength*8, &aeskeyEnc);
> > AES_set_decrypt_key (key, KeyLength*8, &aeskeyDec);
> >
> > /*Encrypting...*/
> > AES_cbc_encrypt(data, buffer, bufferLength, &aeskeyEnc, iv,
> > AES_ENCRYPT);
> > //AES_cbc_encrypt(data, buffer, strlen(data), &aeskeyEnc, iv,
> > AES_ENCRYPT);
> > printf("Encrypted data: %s\n",buffer);
> >
> >
> > /*To Base64 encrypted data */
> > char *base64Buffer = base64(buffer, strlen(buffer));
> > printf("Base64 Encrypted data: %s\n",base64Buffer);
> >
> >
> > /* Unbase64 of encrypted data*/
> > char* test_1 = strcat(base64Buffer,"\n\0");
> > char* unBase64 = unbase64(base64Buffer, strlen(base64Buffer));
> >
> >
> > /*Decypting unBase64...*/
> > AES_cbc_encrypt(unBase64, buffer1,bufferLength, &aeskeyDec, iv1,
> > AES_DECRYPT);
> > //AES_cbc_encrypt(unBase64, buffer1, strlen(unBase64), &aeskeyDec,
> iv1,
> > AES_DECRYPT);
> > printf("Decrypted data: %s \n",buffer1);
> >
> >
> >
> > return(0);
> > }
> >
> >
> >
> ______________________________________________________________________
> OpenSSL Project http://www.openssl.org
> User Support Mailing List [email protected]
> Automated List Manager [EMAIL PROTECTED]
>
--
Karim