Nice catch.  but no, sorry.

The function AES_set_encrypt_key(key32, 256, &aeskey) contains the key length (32 bytes X 8 bits).

I repeated the test from Marek changing the keys and IV to my values, and his demo still works.

So I am continuing my side by side test to see what the difference is.  So far no luck.


-------- Original Message --------
Subject: RE: Looking for (easy) help.
From: Jeremy Farrell <jeremy.farr...@oracle.com>
Date: Fri, May 11, 2012 3:02 pm
To: openssl-users@openssl.org

This is a wild guess, no idea if it's relevant, but the array key32 consists of 33 bytes, 32 containing 0x31 (assuming ASCII) followed by one containing 0x00. Is that how it's meant to be?
 
Regards,
                       jjf
 
From: scott...@csweber.com [mailto:scott...@csweber.com]
Sent: Friday, May 11, 2012 2:43 PM
To: openssl-users@openssl.org
Subject: Looking for (easy) help.
 
(resent, as I never saw this come through the list server)
I am looking for some assistance.  This should be really easy.  But it's not working.  Any quick advice I can get would be appreciated.
 
When I use the API, I get a different cypher text then I get from the command line.
And the command line appears to be the correct one, as it also matches the cypher text I get when I use the PHP interface.
(Once I get the encryption working, I assume the PHP would decrypt it easily, which is my goal)
 
The clear text I am using is simply 6 letters in a file.  The file does NOT contain a newline, and neither does the hardcoded buffer used in the C source.
 
The cypher I get is  (hex string):
from openssl EXE:       aed38175d75ea94e7e59833f11400dcf
From C code:               35709aab6f31555a378bc4a6107f3bd0 
 
 
So, here's the code.  Really easy stuff.  The Key and IV are the same, 
 
---  Command line ----
openssl
        enc -aes-256-cbc
        -in infile.txt -K 3131313131313131313131313131313131313131313131313131313131313131
        -iv fbd070327199c9df7760c5a113bed7a3
        -nosalt -out cypher.bin
 
---- C code:
static unsigned char initVect[] = {
        0xfb,0xd0,0x70,0x32,0x71,0x99,0xc9,0xdf,
        0x77,0x60,0xc5,0xa1,0x13,0xbe,0xd7,0xa3
};
 
 
static const unsigned char key32[] = 
{"11111111111111111111111111111111"};
 
 
void AES256Encrypt(unsigned char  *dst, const char *src, int len) {
 
    AES_KEY aeskey;
    unsigned char iv[sizeof(initVect)]; /* Our own personal copy of the initialization */
    memcpy(iv,initVect,sizeof(initVect)); /* vector, to handle the fact that it's not CONST */
 
    AES_set_encrypt_key(key32, 256, &aeskey);
    AES_cbc_encrypt((unsigned char *)src, (unsigned char *) dst, len, &aeskey, iv, AES_ENCRYPT);
}
 
 
Any help is appreciated!
 
-Scott Weber
 
______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org
______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org

Reply via email to