Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ruby

openssl

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>

like image 386
Nauman Thanvi Avatar asked Apr 18 '12 03:04

Nauman Thanvi


1 Answers

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

like image 161
Nauman Thanvi Avatar answered Sep 22 '22 04:09

Nauman Thanvi