Sign XML document with pfx cert with ruby 3.2.2

36 Views Asked by At

I'm trying to digitally sign an XML document with a pfx certificate in ruby.

I am trying to digitally sign an XML document with a pfx certificate in ruby, the ruby ​​script I am using is this:

require 'openssl'

OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:ciphers] = "RC2-40-CBC"

pfx = OpenSSL::PKCS12.new(File.binread("certificado_2026.pfx"), "geminis2023")
private_key = pfx.key
certificate = pfx.certificate

document = File.read("respuesta_formateada.xml")

signed = OpenSSL::PKCS7::sign(certificate, private_key, document, [], OpenSSL::PKCS7::BINARY)
signed_xml = signed.to_der

File.binwrite("signed-document.xml", signed_xml)

The response I get when running the script is this:

api_2.rb:5:in initialize': PKCS12_parse: unsupported (Global default library context, Algorithm (RC2-40-CBC : 0), Properties ()) (OpenSSL::PKCS12::PKCS12Error) from api_2.rb:5:in new' from api_2.rb:5:in `'

0

There are 0 best solutions below