In ruby, how do I get the subject, issuer etc. after creating an OpenSSL PKCS12 object

醉酒当歌 提交于 2019-12-11 07:25:54

问题


If I use

c = OpenSSL::PKCS12.new data

is there something like c.subject or s.expiry to get these attributes?


回答1:


PKCS#12 is a container format that collects keys and certificates and stores them in a possibly encrypted format. Most of the time, the file is encrypted, so you would "load" the PKCS12 object like this:

p12 = OpenSSL::PKCS12.new(data, "password")

If the password was correct, you will now have access to the key and certificate:

key = p12.key
cert = p12.certificate

With the certificate, you can now access the subject and expiry using the methods of OpenSSL::X509::Certificate. Note that the expiry is accessed by `#not_after'.



来源:https://stackoverflow.com/questions/10646832/in-ruby-how-do-i-get-the-subject-issuer-etc-after-creating-an-openssl-pkcs12

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!