I am wanting to encrypt a file with my public key, my friend told me that this is not a good idea but did not explain why. Can someone explain please.
Asymmetric cryptography has two common use cases:
- Encryption: You process a message or file with the public key of somebody else. Only he/she can decrypt it with his/her private key.
- Signature: You process a message or file with your own private key. The message or file itself can be transmitted unencrypted. It is common to process/sign only a hash of the message/file. Thus everybody can verify with your public key that it was processed by you, because only you (should) have access to your private key.
Encrypting a file with your own public key is none of the above use cases. It doesn't make sense if you store that encrypted file on your computer, because a hacker on your computer can have access to your private key as well.
But your idea makes totally sense, if you want to store your file (for example a backup) on a less secure cloud storage, but keep your private key as secret as it should be. A hacker who breaks in into your cloud storage cannot decrypt the file without breaking in also into your computer.
In short, if you keep your private key separate from your encrypted file I don't see any disadvantage.
Any public-key encryption schemes is bound to increase the size of the data that it enciphers.
While there are more efficient schemes, it is safe to say that a symmetric scheme is orders of magnitude faster and less power hungry than an asymmetric one, at least for decryption.
Private key cryptography is used when the person doing the encryption is different from the person doing the decryption - a situation symmetric cryptography can not handle if the parties can not easily exchange keys.
When private key cryptography is used for transfering larger volumes of data (like in TLS), you normally first encrypt the data with a random symmetric key. Then you encrypt the symmetric key with the recievers public key so that they and nobody else will be able to read it and decrypt the data.
The only disadvantage of Public key encryption is a key distribution problem: if you need to verify/check your file by multiple software instances, i.e. you're signing an upgrade patch, it's a problem to pass your key untampered to the clients, so forging/MitM will be impossible.
If you're about to just encrypt a file - I'd recommend you to use a symmetric key algorithm like AES, because it's hardware accelerated nowadays, almost everywhere. If someone will break in to your cloud or FTP storage and have a file - it will still have the same problem: the decryption key, and if the hacker will break into your PC - it will have full keyset either way. AES256, for example, will be just a way faster to do.