openssl this way can only encrypt small files:
openssl rsautl -encrypt -pubin -inkey public_key.pem -in secret.txt -out secret.enc
openssl as I found suggested here throws an error:
openssl smime -encrypt -aes-256-cbc -binary -in secret.txt -outform DER -out secret.txt.der public_key.pem
not that you're supposed to be using smime because that's for mail but still see the Error:
unable to load certificate
140222726453056:error:0909006C:PEM routines:get_name:no start line:crypto/pem/pem_lib.c:745:Expecting: TRUSTED CERTIFICATE
Why is openssl complaining about a trust certificate? That's my business. I know it means that it wants the PEM to be of a different format rather than taking it personally.
What do I want?
I want to use bash to encrypt any file with strong encryption using a public PEM file (or other public key) so that my project counterpart can use their private key to decrypt it. It would be awesome if I could use powershell native tools as well but that's a big ask and just thought I'd throw it in, in hope of avoiding gitbash for Windows-homed recipients.
I could use gpg but we do not want to introduce generating password generated keys.
openssl smime
with-*form der
actually does CMS, not SMIME, and is not limited to email, but both of those require an X.509 certificate, not a bare public key, for encrypt or verify.openssl
supports two PEM formats for certs, the standard labelCERTIFICATE
orX.509 CERTIFICATE
, see rfc7468 and a private format with some trust info added to the cert, labelled logically enoughTRUSTED CERTIFICATE
.PEM_read*
can show only one label in the error message, so it uses the latter, even though the former is/are also valid and much more common.