* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / sample / openssl / smime_read.rb
blob17394f9b8d35ffc7bd3cea54600b4ff45a9d775c
1 require 'optparse'
2 require 'openssl'
3 include OpenSSL
5 options = ARGV.getopts("c:k:C:")
7 cert_file = options["c"]
8 key_file  = options["k"]
9 ca_path   = options["C"]
11 data = $stdin.read
13 cert = X509::Certificate.new(File::read(cert_file))
14 key = PKey::RSA.new(File::read(key_file))
15 p7enc = PKCS7::read_smime(data)
16 data = p7enc.decrypt(key, cert)
18 store = X509::Store.new
19 store.add_path(ca_path)
20 p7sig = PKCS7::read_smime(data)
21 if p7sig.verify([], store)
22   puts p7sig.data
23 end