class Keystores::Jks::EncryptedPrivateKeyInfo
Attributes
algorithm[RW]
encoded[RW]
encrypted_data[RW]
Public Class Methods
new(opts = {})
click to toggle source
You can pass either an ASN.1 encryptedPrivateKeyInfo object or the encrypted bytes and the encryption algorithm.
@param [Hash] opts @option opts [String] :encoded The ASN.1 encoded encrypted private key info @option opts [String] :algorithm The encryption algorithm @option opts [String] :encrypted_data The encrypted key bytes
# File lib/keystores/jks/encrypted_private_key_info.rb, line 23 def initialize(opts = {}) # Parses from encoded private key if opts.has_key?(:encoded) encoded = opts[:encoded] @asn1 = OpenSSL::ASN1.decode(encoded) @encrypted_data = @asn1.value[1].value @algorithm = @asn1.value[0].value[0].value @encoded = encoded else @algorithm = opts[:algorithm] @encrypted_data = opts[:encrypted_data] @encoded = encode(@algorithm, @encrypted_data) end end
Private Instance Methods
encode(algorithm, encrypted_data)
click to toggle source
Java actually encodes:
EncryptedPrivateKeyInfo ::= SEQUENCE { SEQUENCE { null, encryptionAlgorithm AlgorithmIdentifier}, encryptedData OCTET STRING }
# File lib/keystores/jks/encrypted_private_key_info.rb, line 47 def encode(algorithm, encrypted_data) a = OpenSSL::ASN1::ObjectId.new(algorithm) null = OpenSSL::ASN1::Null.new(nil) oid_sequence = OpenSSL::ASN1::Sequence.new([a, null]) d = OpenSSL::ASN1::OctetString.new(encrypted_data) OpenSSL::ASN1::Sequence.new([oid_sequence, d]).to_der end