openssl equivalent command in ruby

大憨熊 提交于 2019-12-04 19:25:56

Should be easy:

#!/usr/bin/env ruby
# export-der.rb

require 'openssl'

def export_der(pass, key, cert, out)
  key    = OpenSSL::PKey.read File.read(key)
  cert   = OpenSSL::X509::Certificate.new File.read(cert)
  name   = nil # not sure whether this is allowed
  pkcs12 = OpenSSL::PKCS12.create(pass, name, key, cert)
  File.open(out, 'w'){|f| f << pkcs12.to_der }
end

puts 'Password:'
export_der($stdin.read, *ARGV)

And call it this way (untested ;-)):

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