Openssl encrypt / decrypt question


Hi all,

I’m attempting to encrypt and decrypt a string, and am having some
issues with the decrypt side. I’m using ruby 1.8.4 on gentoo.

My code looks something like this:

-----code starts-----
require ‘openssl’

Load up sender key pair

from_cert =“send_cert.pem”))
from_key =“send_key.pem”))

Load up recipient key pair (

to_cert =“rcpt_cert.pem”))
to_key =“rcpt_key.pem”))

Basic data

data = “test this out”

Sign message

from_signed = PKCS7::sign(from_cert, from_key, data, [], PKCS7::BINARY)

The next line emits the data correctly


Encrypt signed message

from_encrypted = PKCS7::encrypt([to_cert], from_signed.to_der,
Cipher::Cipher::new(“DES3”), PKCS7::BINARY)

This is the data format I send to the recipient.

from_message = from_encrypted.to_pem

Pretend that I’m receiving this on the ‘to’ side.

to_encrypted =
to_decrypted =, to_cert,

See who signed the message:

to_decrypted.signers.each { |signer|
print “#{}\n”

This should emit the data, but instead prints nothing.

print “#{}\n”
-----code ends-----

So… I know that the encryption works, because a third party can
decrypt messages I send them. However, in this testing setup, I can see
who the signer is, but there’s no data (output is ‘nil’).

Anyone know what I’m doing wrong?