Why can't I encrypt with OpenSSL?
encryption, openssl, rsa
Solution
You forgot to specify that it's a public key, it needs to be done explicitly. This works (I'm using `pkeyutl`, the specific "utl"s are deprecated):
openssl pkeyutl -encrypt -in myfile.txt -pubin -inkey public.pem -out file.ssl
You have to be careful where you put the `-pubin` - if it is specified after the `-inkey public.pem` for example, you will again receive the same error as before. Yeah, I know.
Problem
I'm having trouble creating a public/private key pair and using it to encrypt a file. First I generate the private key: ``` openssl genrsa -out private.pem 2048 ``` Then I extract the public key: ``` openssl rsa -in private.pem -out public.pem -outform PEM -pubout ``` so that I can encrypt my file: ``` openssl rsautl -encrypt -inkey public.pem -in myfile.txt -out file.ssl ``` but then I'm told: ``` Loading 'screen' into random state - done unable to load Private Key 7064:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:696: Expecting: ANY PRIVATE KEY ``` I don't understand... why is it trying to load a private key? How do I encrypt a file using the public key?