Module: Checksign
- Includes:
- Origami
- Defined in:
- lib/Sign.rb
Overview
require ‘origami’
Constant Summary collapse
- OUTPUTFILE =
Code below is based on documentation available on www.ruby-doc.org/stdlib-1.9.3/libdoc/openssl/rdoc/OpenSSL.html
"test.pdf"
Class Method Summary collapse
-
.Signpdf ⇒ Object
for PDF Sign.
-
.Verifypdf ⇒ Object
for PDF verification.
Class Method Details
.Signpdf ⇒ Object
for PDF Sign
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/Sign.rb', line 21 def self.Signpdf key = OpenSSL::PKey::RSA.new 2048 open 'private_key.pem', 'w' do |io| io.write key.to_pem end open 'public_key.pem', 'w' do |io| io.write key.public_key.to_pem end cipher = OpenSSL::Cipher::Cipher.new 'AES-128-CBC' pass_phrase = 'Origami rocks' key_secure = key.export cipher, pass_phrase open 'private_key.pem', 'w' do |io| io.write key_secure end #Create the certificate name = OpenSSL::X509::Name.parse 'CN=nobody/DC=example' cert = OpenSSL::X509::Certificate.new cert.version = 2 cert.serial = 0 cert.not_before = Time.now cert.not_after = Time.now + 3600 cert.public_key = key.public_key cert.subject = name contents = ContentStream.new.setFilter(:FlateDecode) contents.write OUTPUTFILE,:x => 350, :y => 750, :rendering => Text::Rendering::STROKE, :size => 30 pdf = PDF.read('kimbo.pdf') # Open certificate files sigannot = Annotation::Widget::Signature.new sigannot.Rect = Rectangle[:llx => 89.0, :lly => 386.0, :urx => 190.0, :ury => 353.0] #page.add_annot(sigannot) # Sign the PDF with the specified keys pdf.sign(cert, key, :method => 'adbe.pkcs7.sha1', :annotation => sigannot, :location => 'India', # :contact => nil, :reason => 'Proof of Concept' ) # puts pdf # Save the resulting file pdf.save(OUTPUTFILE) end |
.Verifypdf ⇒ Object
for PDF verification
83 84 85 |
# File 'lib/Sign.rb', line 83 def self.Verifypdf end |