When encrypting, you use their public key to write a message and they use their private key to read it.
When signing, you use your private key to write message's signature, and they use your public key to check if it's really yours.
I want to use my private key to generate messages so only I can possibly be the sender.
I want my public key to be used to read the messages and I do not care who reads them
This is signing, it is done with your private key.
I want to be able to encrypt certain information and use it as a product key for my software.
I only care that I am the only one who can generate these.
If you only need to know it to yourself, you don't need to mess with keys to do this. You may just generate random data and keep it in a database.
But if you want people to know that the keys are really yours, you need to generate random data, keep in it a database AND sign it with your key.
I would like to include my public key in my software to decrypt/read the signature of the key.
You'll probably need to purchase a certificate for your public key from a commercial provider like Verisign or Thawte, so that people may check that no one had forged your software and replaced your public key with theirs.
You are mistaken. RSA is not a block cipher, so you cannot really talk about the block size of it.
The output of a RSA encryption will have the same length as the RSA modulus. You have not indicated any RSA key in your code, so the runtime will (as far as I recall) use a default key. That key apparently has a 1024 bit modulus, which explains the output length.
You might want to look into AES encryption instead. For many reasons you should normally only use RSA to encrypt a key and then use AES or a similar symmetric cipher algorithm to encrypt your actual text.
AES is a block cipher with block size 16 bytes, so that will (depending on which padding you use and how you transport your initialization vector) encrypt 16 bytes of plain data to 16 bytes of encrypted data.
Best Answer
Yes, it is.
The output-size should always equals the size of the
Modulus
(part of the key), so:If it is not, there exist numerous attacks on RSA, see here for basic information about that.
So to guarantee that the output is
2048 bit
even when the input to encrypt is, let's say7
,a padding must always be applied!