Ruby code for openssl to generate fingerprint -


i need ruby equivalent of following: openssl x509 -sha1 -fingerprint -noout -in cert.pem

the code wrote is:

 data = file.read("cert.pem")  data["-----begin certificate-----\n"]=""  data["-----end certificate-----\n"]=""  openssl::digest::sha1.new(base64.encode64(data)) 

this code not generate same fingerprint openssl cli command does.

any idea may doing wrong?

as gtrig mentions, openssl command line builds fingerprint hashing der encoding of certificate, not base64 pem representation. can parse using pure openssl:

file_data = file.read("cert.pem") cert = openssl::x509::certificate.new(file_data) puts openssl::digest::sha1.new(cert.to_der).to_s 

shameless plug: r509 can so:

cert = r509::cert.load_from_file("cert.pem") puts cert.fingerprint('sha1') 

if need in colon separated form can take hash , "fingerprint".scan(/../).map{ |s| s.upcase }.join(":")


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -