Class: XmlSigner::Signer

Inherits:
Object
  • Object
show all
Defined in:
lib/xml_signer/xml_signer.rb

Instance Method Summary collapse

Constructor Details

#initialize(pfx_file, pfx_password) ⇒ Signer

Returns a new instance of Signer.



8
9
10
11
12
13
14
# File 'lib/xml_signer/xml_signer.rb', line 8

def initialize(pfx_file, pfx_password)
  @pfx_file = pfx_file
  @pfx_password = pfx_password
  @p12 = OpenSSL::PKCS12.new(File.read(@pfx_file), @pfx_password)
  @cert = @p12.certificate
  @key = @p12.key
end

Instance Method Details

#sign(xml_string) ⇒ Object



16
17
18
19
20
21
# File 'lib/xml_signer/xml_signer.rb', line 16

def sign(xml_string)
  doc = Nokogiri::XML(xml_string)
  signature = generate_signature_element(doc)
  doc.root.add_child(signature)
  doc.to_xml
end