2003-07-23 12:12:24 -04:00
|
|
|
require 'openssl'
|
2007-12-24 02:31:23 -05:00
|
|
|
require 'optparse'
|
2003-07-23 12:12:24 -04:00
|
|
|
include OpenSSL
|
|
|
|
|
2007-12-24 02:31:23 -05:00
|
|
|
options = ARGV.getopts("c:k:r:")
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2007-12-24 02:31:23 -05:00
|
|
|
cert_file = options["c"]
|
|
|
|
key_file = options["k"]
|
|
|
|
rcpt_file = options["r"]
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
cert = X509::Certificate.new(File::read(cert_file))
|
|
|
|
key = PKey::RSA.new(File::read(key_file))
|
|
|
|
|
|
|
|
data = "Content-Type: text/plain\r\n"
|
|
|
|
data << "\r\n"
|
|
|
|
data << "This is a clear-signed message.\r\n"
|
|
|
|
|
|
|
|
p7sig = PKCS7::sign(cert, key, data, [], PKCS7::DETACHED)
|
|
|
|
smime0 = PKCS7::write_smime(p7sig)
|
|
|
|
|
|
|
|
rcpt = X509::Certificate.new(File::read(rcpt_file))
|
|
|
|
p7enc = PKCS7::encrypt([rcpt], smime0)
|
2011-05-15 07:55:52 -04:00
|
|
|
print PKCS7::write_smime(p7enc)
|