class Izokatu::Openssl::PublicKey::EC::Decrypter

OpenSSL public key EC decrypter

Constants

DEFAULT_ECIES_OPTIONS

Default options for ECIES

Attributes

ecies_cipher[R]

@return [String] ECIES cipher name

ecies_digest[R]

@return [String] ECIES digest name

ecies_kdf_digest[R]

@return [String] ECIES KDF digest name

ecies_mac_digest[R]

@return [String] ECIES MAC digest name

ecies_mac_length[R]

@return [Symbol] ECIES MAC length

private_key[R]

@return [String] private key string for decryption

Public Class Methods

new(encrypted_data:, private_key:, ecies_options:) click to toggle source
Calls superclass method Izokatu::Decrypter::new
# File lib/izokatu/openssl/public_key/ec/decrypter.rb, line 32
def initialize(encrypted_data:, private_key:, ecies_options:)
  # Initialize options for OpenSSL EC decryption
  #
  # @param encrypted_data (#encrypted_data)
  # @param private_key (#private_key)
  # @param ecies_options Hash with ECIES options
  #
  # @since 0.1.0
  super(encrypted_data: encrypted_data)
  initialize_private_key!(private_key)
  initialize_ecies_options!(ecies_options || DEFAULT_ECIES_OPTIONS)
  initialize_decrypter!
end

Public Instance Methods

initialize_decrypter!() click to toggle source

Initialize decrypter

@return [ECIES::Crypt] decrypter instance

@since 0.1.0

# File lib/izokatu/openssl/public_key/ec/decrypter.rb, line 80
def initialize_decrypter!
  @decrypter = ECIES::Crypt.new(
    cipher: ecies_cipher,
    digest: ecies_digest,
    mac_length: ecies_mac_length,
    kdf_digest: ecies_kdf_digest,
    mac_digest: ecies_mac_digest
  )
end
initialize_ecies_options!(ecies_options) click to toggle source

Initialize ECIES options

@param ecies_options Hash with ECIES options

@since 0.1.0

# File lib/izokatu/openssl/public_key/ec/decrypter.rb, line 66
def initialize_ecies_options!(ecies_options)
  @ecies_cipher = ecies_options[:ecies_cipher]
  @ecies_digest = ecies_options[:ecies_digest]
  @ecies_mac_length = ecies_options[:ecies_mac_length]
  @ecies_kdf_digest = ecies_options[:ecies_kdf_digest]
  @ecies_mac_digest = ecies_options[:ecies_mac_digest]
end
initialize_private_key!(private_key) click to toggle source

Initialize EC private key from private key string

@param private_key (private_key)

@return [OpenSSL:PKey::EC] OpenSSL private key instance

@since 0.1.0

# File lib/izokatu/openssl/public_key/ec/decrypter.rb, line 54
def initialize_private_key!(private_key)
  raise 'ERROR: No private key!' unless private_key

  @private_key = OpenSSL::PKey.read(private_key)
end

Private Instance Methods

decrypt_data!() click to toggle source

Decrypting data

@return [Hash] decrypted data

@since 0.1.0

# File lib/izokatu/openssl/public_key/ec/decrypter.rb, line 98
def decrypt_data!
  { decrypted_data_string: decrypter.decrypt(private_key, encrypted_data) }
end