Class: OpenSSL::PKCS12
- Inherits:
-
Object
- Object
- OpenSSL::PKCS12
- Defined in:
- lib/shared/openssl/pkcs12.rb
Instance Attribute Summary collapse
-
#certificate ⇒ Object
readonly
Returns the value of attribute certificate.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(pass, name, key, cert) ⇒ PKCS12
constructor
A new instance of PKCS12.
- #to_der ⇒ Object
Constructor Details
#initialize(pass, name, key, cert) ⇒ PKCS12
Returns a new instance of PKCS12.
22 23 24 25 26 27 |
# File 'lib/shared/openssl/pkcs12.rb', line 22 def initialize(pass, name, key, cert) @pass = pass @name = name @key = key @certificate = cert end |
Instance Attribute Details
#certificate ⇒ Object (readonly)
Returns the value of attribute certificate.
20 21 22 |
# File 'lib/shared/openssl/pkcs12.rb', line 20 def certificate @certificate end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
20 21 22 |
# File 'lib/shared/openssl/pkcs12.rb', line 20 def key @key end |
Class Method Details
.create(pass, name, key, cert) ⇒ Object
14 15 16 17 18 |
# File 'lib/shared/openssl/pkcs12.rb', line 14 def self.create(pass, name, key, cert) pkcs12 = self.new(pass, name, key, cert) pkcs12.generate pkcs12 end |
Instance Method Details
#generate ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/shared/openssl/pkcs12.rb', line 29 def generate key_reader = StringReader.new(key.to_pem) key_pair = PEMReader.new(key_reader).read_object cert_input_stream = StringBufferInputStream.new(certificate.to_pem) certs = CertificateFactory.get_instance("X.509").generate_certificates(cert_input_stream) store = KeyStore.get_instance("PKCS12", "BC") store.load(nil, nil) store.set_key_entry(@name, key_pair.get_private, nil, certs.to_array(Java::java.security.cert.Certificate[certs.size].new)) pkcs12_output_stream = ByteArrayOutputStream.new store.store(pkcs12_output_stream, @pass.to_java.to_char_array) @der = String.from_java_bytes(pkcs12_output_stream.to_byte_array) end |
#to_der ⇒ Object
46 47 48 |
# File 'lib/shared/openssl/pkcs12.rb', line 46 def to_der @der end |