views:

263

answers:

2

Here is what I've tried:

Encrypt message w/ my public key

openssl enc -aes-256-cbc -salt -kfile key.pub -in message.txt -out message.enc

Decrypt message using my private key

openssl enc -d -aes-256-cbc -salt -in message.enc -pass file:mykey.pem 

Error from decryption

bad decrypt
452:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:330:
A: 

Encrypt:

openssl enc -aes-256-cbc -salt -pass file:password.txt -in message.txt -out message.enc

Decrypt:

openssl enc -aes-256-cbc -d -salt -pass file:password.txt -in message.enc -out message.dec

Where the first line of the file password.txt contains your password.

echo
This method works fine using a simple password text file -- but I need to encrypt using my public key and decrypt using my private one.
wrench_hc
This worked: openssl rsautl -pubin -inkey key.pub -encrypt -in message.txt -out message.encopenssl rsautl -inkey privkey.pem -decrypt -in message.enc -out message.dec
wrench_hc
A: 

This worked:

openssl rsautl -pubin -inkey key.pub -encrypt -in message.txt -out message.enc

openssl rsautl -inkey privkey.pem -decrypt -in message.enc -out message.dec

wrench_hc
The problem with that is you can only use it to encrypt small messages. If you try to encrypt anything over the size of your key minus 11 bytes you'll get an error message like: rsa routines:RSA_padding_add_PKCS1_type_2:data too large for key size
Mike Bethany