My understanding is that the public key can be used for encryption and the private for decryption and that the public key cannot decrypt the file encrypted by the same public key. Did I misunderstand or am I doing something incorrectly?
1) generate a key
openssl genrsa -out ./private.pem 2048
2) generate a public key
openssl rsa -in ./private.pem -pubout > ./public.pem
3) encrypt a small text file
openssl enc -in ./in.txt -out ./out.enc -e -aes256 -k ./public.pem
4) decrypt file using PUBLIC key
openssl enc -in ./out.enc -out ./out.txt -d -aes256 -k ./public.pem
The last step can decrypt the "out.enc" file. Not what I wanted or expected.
public.pem
, since apart from being a public key is a regular file – IljaBek