Nauman Thanvi
Nauman Thanvi

Reputation: 153

Why openssl on windows produces error but not on centos: PKCS12_parse: mac verify failure (OpenSSL::PKCS12::PKCS12Error)

require 'openssl'

if ARGV.length == 2
    pkcs12 = OpenSSL::PKCS12.new(File.read(ARGV[0]), ARGV[1])
    p pkcs12.certificate
else
    puts "Usage: load_cert.rb <path_to_cert> <cert_password>"
end

Running this produces error on windows but not in linux.

Error:

OpenSSL::PKCS12::PKCS12Error: PKCS12_parse: mac verify failure
from (irb):21:in initialize
from (irb):21:in new
from (irb):21
from C:/Ruby192/bin/irb:12:in <main>

Upvotes: 7

Views: 6903

Answers (1)

Nauman Thanvi
Nauman Thanvi

Reputation: 153

File.read("UserCert.p12", "rb")

Problem was ruby by default read file as text and need to force to read file as binary, it solves the problem

Upvotes: 8

Related Questions