Class: Virgil::Crypto::VirgilPrivateKeyExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/virgil/crypto/private_key_exporter.rb

Overview

Provides export [PrivateKey] into its material representation bytes and import [PrivateKey] from its material representation bytes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(crypto: nil, password: nil) ⇒ VirgilPrivateKeyExporter

Initializes a new instance of the [VirgilPrivateKeyExporter] class. that is used for export and import of [PrivateKey]

Parameters:

  • password (String) (defaults to: nil)

    private key password, nil by default.

  • crypto (defaults to: nil)

    the instance of [Crypto::VirgilCrypto]



47
48
49
50
# File 'lib/virgil/crypto/private_key_exporter.rb', line 47

def initialize(crypto: nil, password: nil)
  @password = password
  @virgil_crypto = crypto || VirgilCrypto.new
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



41
42
43
# File 'lib/virgil/crypto/private_key_exporter.rb', line 41

def password
  @password
end

#virgil_cryptoObject (readonly)

Returns the value of attribute virgil_crypto.



40
41
42
# File 'lib/virgil/crypto/private_key_exporter.rb', line 40

def virgil_crypto
  @virgil_crypto
end

Instance Method Details

#export_private_key(private_key) ⇒ Crypto::Bytes

Exports the provided [PrivateKey] into material representation bytes.

Parameters:

  • private_key (PrivateKey)

    The private key.

Returns:



55
56
57
# File 'lib/virgil/crypto/private_key_exporter.rb', line 55

def export_private_key(private_key)
  @virgil_crypto.export_private_key(private_key, @password)
end

#import_private_key(private_key_bytes) ⇒ VirgilPrivateKey

Imports the private key from its material representation.

Parameters:

Returns:



62
63
64
# File 'lib/virgil/crypto/private_key_exporter.rb', line 62

def import_private_key(private_key_bytes)
  @virgil_crypto.import_private_key(private_key_bytes, @password)
end