AES

Dec 24, 2012 at 11:35am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
int main()
{
    aes_context ctx;
    
    CHAR *input = "Sample text abc";
    CHAR *out;
    CHAR *secret_key = "secret key";

    BYTE* buf = (BYTE*)malloc(16);
    BYTE* key = (BYTE*)malloc(32);

    memset(buf,0,16);
    memset(key,0,32);
    memcpy( buf, input, 16);

    memcpy( key, secret_key, 32);
    aes_set_key( &ctx, key, 256);

    aes_encrypt( &ctx, buf, buf );
    out=(CHAR*)buf;
    MessageBox(0, out, "Encrypted text", MB_OK);

    aes_decrypt( &ctx, buf, buf );
    out=(CHAR*)buf;
    MessageBox(0, out, "Decrypted text", MB_OK);

    return 0;
}

hey guys,
im having problem with this AES example above...only the first 15 characters will be encrypted..it cant encrypt all character if the text if it is more than 15 characters

i really wanted to do is to encrypt a binary file (whole file)
Dec 24, 2012 at 11:49am
Try using std :: string or you must count your file size then allocate dynamic memory to store the whole text
Dec 24, 2012 at 1:56pm
Do you really mean this?
 
memcpy( key, secret_key, 32);

The password will include any random bytes that follow secret_key.

I expect it just encrypt's 16 byte blocks. If you're using OpenSSL, you really ought to be using the Envelope functions, as they deal with blocks and padding, otherwise you have to do it yourself.
Dec 24, 2012 at 2:20pm
AES takes 16 bytes to another 16 bytes. To use it on more data, see http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation
There should be functions for all kinds of modes in, wherever you're getting this aes_encrypt() from.
Topic archived. No new replies allowed.