Hi,

I'm trying to make a function encoding a string in AES
and then to encode it in base64, the prototype would be like :

string AESEncode(char *cleartext, char *key);

I watched on the forum and source code... I found a post with
someone encoding/decoding a buffer like that :

>>CTR_Mode<AES>::Encryption aes_ctr_enc(s_key, 16, s_iv);
>>aes_ctr_enc.ProcessString((unsigned char*)buf, buf_size);

I thought an encrypted buffer with AES could be a little bit
bigger than the clear one (since it's by block and not just
per caracter encoding), but maybe I'm wrong... Is there a
short way to encode with AES using string objects, right now
I just did something that looks like black magic, just for
testing, but I'm sure it can be MUCH cleaner and simpler,
here's the code :

string AESEncryptString(char *cleartext, char *key)
{
        string clearstr = cleartext;
        string result;
        char *ok = new char[strlen(cleartext)+32];

        strnset(ok, 0, strlen(cleartext)+32);

        CTR_Mode<AES>::Encryption aes((const unsigned char*)key, strlen(key));

        aes.ProcessString((unsigned char*)ok, (const unsigned char*)cleartext,
strlen(cleartext));
        
        clearstr = ok;
        delete ok;

        StringSource(clearstr, true, new Base64Encoder(new StringSink(result)));       
 

        return result;
}

Thanks for help...

Florent,


>>And, simeple example for AES with Counter mode.

>>CTR_Mode<AES>::Encryption aes_ctr_enc(s_key, 16, s_iv);
>>aes_ctr_enc.ProcessString((unsigned char*)buf, buf_size);

>>CTR_Mode<AES>::Decryption aes_ctr_dec(s_key, 16, s_iv);
>>aes_ctr_dec.ProcessString((unsigned char*)buf, buf_size);
_____________________________________________________________________
GRAND JEU SMS : Pour gagner un NOKIA 7650, envoyez le mot IF au 61321
(prix d'un SMS + 0.35 euro). Un SMS vous dira si vous avez gagn�.
R�glement : http://www.ifrance.com/_reloc/sign.sms

Reply via email to