[Botan-devel] RSA not decrypting 512 bytes

Jack Lloyd lloyd at randombit.net
Wed Jul 7 13:53:56 EDT 2010

On Wed, Jul 07, 2010 at 10:43:38AM -0700, tony baba wrote:
> I am using exactly the same code provided in the stock
> examples. I've just added the rsa_enc.cpp in a empty windows console
> project in Visual Studio 2005, compiled and linked with botan.lib
> and run the resultant executable on the command line. Same is done
> with rsa_dec.cpp.


How big is the encrypted file, compared to your input? It should be
quite a bit larger since it will contain the encrypted key, and the
whole thing will be base64 encoded.

That rsa_dec doesn't complain that the authentication code is invalid
suggests that for whatever reason, rsa_enc isn't actually seeing the
whole file. Is this file raw binary? IIRC, Windows has some weird
file-end convention which this may be triggering. If you are giving it
binary data, try this change to rsa_enc:

--- doc/examples/rsa_enc.cpp    d3d0a9c613c75dd7be95f67bdd2c31bb3e7adbc8
+++ doc/examples/rsa_enc.cpp    4719cd03a067d7457e90e556d0abd43943fe89ff
@@ -47,7 +47,7 @@ int main(int argc, char* argv[])
       return 1;
-   std::ifstream message(argv[2]);
+   std::ifstream message(argv[2], std::ios::binary);
       std::cout << "Couldn't read the message file." << std::endl;

More information about the botan-devel mailing list