Hi vince,

This comment is more directed at design...

> The odd thing is thou that using 10-22 as the max input buffer size in
> the fread works..  But other values like 23,32,64,100, etc..  do not
> work.
Typically, one uses a symmetric cipher to encrypt things such as files
and graphics. If one uses an asymmetric cipher (such as RSA), there is
a limit on the size of the data - when written out as a byte array
(and then interpreted as a number), the 'value' of the byte array must
be less than the modulos (loosely speaking). Hand waving is going on
here, but here is a concrete example the emphasizes the point. Suppose
you had a three byte file with the letters ABC in it. These are ASCII
encoded as 0x65, 0x66, 0x67. Create the array: 656667. Treat it as
anumber: 656,667. Now, the modulos must be greater than 656,667 to
properly encrypt the data.

Here is how I would change the design:
1) Encrypt files with AES
2) Encrypt the AES key with RSA
3) Place the encrypted AES key in the executable's binary

(2) and (3) occur so that the AES key is not hanging out in the 'plain
text' in the .data section

Jeff

On 9/6/07, l0wfreq <[EMAIL PROTECTED]> wrote:
>
> After having no luck getting FileSource to work properly, I have
> gotten a buffer by buffer version encrypting the data;
>
>
> string PrivateKeyFile = "key.pv";
> string PublicKeyFile  = "key.pb";
> FileSource pubFile( PublicKeyFile.c_str(),true, new HexDecoder );
> FileSource privFile( PrivateKeyFile.c_str(),true, new HexDecoder);
> RSAES_OAEP_SHA_Encryptor Encryptor ( pubFile );
> RSAES_OAEP_SHA_Decryptor Decryptor( privFile );
>
> ......................... fopen, variable inits and error checking
> omitted here .........................
>
> while(!feof(fptr)){
>        fread_result=fread(read_buffer,1,22,fptr);
>        if(fread_result>0){
>                Encryptor.Encrypt(GlobalRNG(),(byte*)read_buffer,fread_result,
> (byte*) cipher_buffer);
>                cipherTextSize = (int)Encryptor.CiphertextLength(fread_result);
>                fwrite(cipher_buffer,1,cipherTextSize,encrfptr);
>        }
> }
>
> The odd thing is thou that using 10-22 as the max input buffer size in
> the fread works..  But other values like 23,32,64,100, etc..  do not
> work.
>
> For example fread_result=fread(read_buffer,1,32,fptr); Causes a memory
> violation inside of Encryptor.Encrypt.
>
> My three questions are;
>
> 1. Why can't I allocate a larger buffer to encrypt
> 2. Is this method really intended to encrypt binary data
> 3. Should I always expect a 2:1 byte count from plaintext length to
> ciphertext length
>
> Everyones help is greatly apprecaited. Once I have a working example I
> will post for everyone. This is an awesome toolkit, I have just not
> found any great RSA file encryption application example. Everything is
> little message tests.
>
> Thanks,
>
> l0wfreq

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [EMAIL PROTECTED]
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---

Reply via email to