class Izokatu::Openssl::PublicKey::EC::Encrypter

OpenSSL public key EC encrypter

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

public_key[R]

@return [String] public key string for decryption

Public Class Methods

new(clear_data:, public_key:, ecies_options:) click to toggle source

Initialize options for OpenSSL EC encryption

@param clear_data (clear_data) @param public_key (public_key) @param ecies_options Hash with ECIES options

@since 0.1.0

Calls superclass method Izokatu::Encrypter::new
# File lib/izokatu/openssl/public_key/ec/encrypter.rb, line 39
def initialize(clear_data:, public_key:, ecies_options:)
  super(clear_data: clear_data)
  @public_key = public_key
  initialize_public_key!(public_key)
  initialize_ecies_options!(ecies_options || DEFAULT_ECIES_OPTIONS)
  initialize_encrypter!
end

Public Instance Methods

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/encrypter.rb, line 67
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_encrypter!() click to toggle source

Initialize encrypter

@return [ECIES::Crypt] encrypter instance

@since 0.1.0

# File lib/izokatu/openssl/public_key/ec/encrypter.rb, line 81
def initialize_encrypter!
  @encrypter = 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_public_key!(public_key) click to toggle source

Initialize EC public key from public key string

@param public_key (public_key)

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

@since 0.1.0

# File lib/izokatu/openssl/public_key/ec/encrypter.rb, line 55
def initialize_public_key!(public_key)
  raise 'ERROR: No public key!' unless public_key

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

Private Instance Methods

encrypt_data!() click to toggle source

Encrypting data

@return [Array] encrypted data with empty hash in place of params

@since 0.1.0

# File lib/izokatu/openssl/public_key/ec/encrypter.rb, line 99
def encrypt_data!
  [{ encrypted_data_string: encrypter.encrypt(public_key, clear_data) }, {}]
end