0
我有一個私鑰的pem證書。 我使用上述信息產生被密碼保護如下P12證書:紅寶石編碼一個p12證書(二進制)併發送爲json響應
def p12_cert
ca_cert = x509_cert(File.open("#{root}/ca-cert.crt").read)
p12 = OpenSSL::PKCS12.create(@random_pass, 'My Certificate',
rsa_pkey(private_key), x509_cert(public_cert), [ca_cert])
create_file('p12', p12.to_der, ':ASCII-8BIT')
end
的問題是,這是二進制格式,無法通過JSON API傳輸。
有人可以如何我如何編碼它(也許base64),以便這可以作爲JSON響應發送?
編輯:我打開閱讀P12文件,然後試圖使用Base64編碼,得到如下:
irb(main):017:0> enc_p12 = Base64.encode64(p12) TypeError: no implicit conversion of OpenSSL::PKCS12 into String
有些功能並不在https://github.com/Mitka20/tango_api/blob/2cc0127b8fc601526ddd000ff1ac46d6531592c0/tango_api.rb代碼幫助嗎? – sheppe
@sheppe。我不確定。在你的例子中,你讀了p12文件,但我不知道如何通過JSON(非二進制格式)發送它 – Micheal
密鑰附加到請求中的一行:https.key = p12.key 另外,這不是我的代碼,但似乎相關。 :) – sheppe