Sha256: 80a7f1f5ebc5782b35551be35ed0574788a85ea752b41608af26f3e57eb8d369
Contents?: true
Size: 1.51 KB
Versions: 1
Compression:
Stored size: 1.51 KB
Contents
require 'signer' module Eet module Utils def self.create_pkp(message, certificate) digest = OpenSSL::Digest::SHA256.new signature = certificate.key.sign(digest, serialize_pkp_data(message)) Base64.encode64(signature).delete("\n") end def self.create_bkp(pkp_value) decoded = Base64.decode64(pkp_value) digest = Digest::SHA1.digest(decoded) ret = '' encoded = digest.each_char do |c| ch = c.ord.to_s(16) ch = '0' + ch if ch.size == 1 ret += ch end ret.upcase.chars.each_slice(8).map(&:join).join('-') end def self.sign(xml, certificate) signer = Signer.new(xml) signer.cert = OpenSSL::X509::Certificate.new(certificate.certificate) signer.private_key = OpenSSL::PKey::RSA.new(certificate.key, 'eet') signer.security_node = signer.document.children.first.children.first.children.first signer.digest_algorithm = :sha256 signer.signature_digest_algorithm = :sha256 signer.ds_namespace_prefix = 'ds' signer.security_token_id = 'A79845F15C5549CA0514761283545705' signer.digest!(signer.document.at_xpath('//soap:Body'), inclusive_namespaces: ['']) signer.sign!(security_token: true, inclusive_namespaces: ['soap']) signer.to_xml end def self.serialize_pkp_data(message) [message.dic_popl, message.id_provoz, message.id_pokl, message.porad_cis, message.dat_trzby, message.celk_trzba].join('|') end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
eet-0.2.0 | lib/eet/utils.rb |