Class: Izokatu::Openssl::PublicKey::EC::Encrypter

Inherits:
Encrypter
  • Object
show all
Defined in:
lib/izokatu/openssl/public_key/ec/encrypter.rb

Overview

OpenSSL public key EC encrypter

Constant Summary collapse

DEFAULT_ECIES_OPTIONS =

Default options for ECIES

{
  ecies_cipher: 'AES-256-CTR',
  ecies_digest: 'SHA512',
  ecies_mac_length: :full,
  ecies_kdf_digest: 'SHA512',
  ecies_mac_digest: 'SHA512'
}.freeze

Constants inherited from Encrypter

Encrypter::DEFAULT_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from Encrypter

#clear_data, #encrypted_data, #encrypter

Instance Method Summary collapse

Methods inherited from Encrypter

#import_clear_data!, #perform

Methods included from Callable

#call

Constructor Details

#initialize(clear_data:, public_key:, ecies_options:) ⇒ Encrypter

Initialize options for OpenSSL EC encryption

Parameters:

Since:

  • 0.1.0



39
40
41
42
43
44
45
# 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

Instance Attribute Details

#ecies_cipherString (readonly)

Returns ECIES cipher name.

Returns:

  • (String)

    ECIES cipher name



12
13
14
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 12

def ecies_cipher
  @ecies_cipher
end

#ecies_digestString (readonly)

Returns ECIES digest name.

Returns:

  • (String)

    ECIES digest name



14
15
16
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 14

def ecies_digest
  @ecies_digest
end

#ecies_kdf_digestString (readonly)

Returns ECIES KDF digest name.

Returns:

  • (String)

    ECIES KDF digest name



18
19
20
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 18

def ecies_kdf_digest
  @ecies_kdf_digest
end

#ecies_mac_digestString (readonly)

Returns ECIES MAC digest name.

Returns:

  • (String)

    ECIES MAC digest name



20
21
22
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 20

def ecies_mac_digest
  @ecies_mac_digest
end

#ecies_mac_lengthSymbol (readonly)

Returns ECIES MAC length.

Returns:

  • (Symbol)

    ECIES MAC length



16
17
18
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 16

def ecies_mac_length
  @ecies_mac_length
end

#public_keyString (readonly)

Returns public key string for decryption.

Returns:

  • (String)

    public key string for decryption



10
11
12
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 10

def public_key
  @public_key
end

Instance Method Details

#encrypt_data!Array (private)

Encrypting data

Returns:

  • (Array)

    encrypted data with empty hash in place of params

Since:

  • 0.1.0



99
100
101
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 99

def encrypt_data!
  [{ encrypted_data_string: encrypter.encrypt(public_key, clear_data) }, {}]
end

#initialize_ecies_options!(ecies_options) ⇒ Object

Initialize ECIES options

Parameters:

  • ecies_options

    Hash with ECIES options

Since:

  • 0.1.0



67
68
69
70
71
72
73
# 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!ECIES::Crypt

Initialize encrypter

Returns:

  • (ECIES::Crypt)

    encrypter instance

Since:

  • 0.1.0



81
82
83
84
85
86
87
88
89
# 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) ⇒ OpenSSL:PKey::EC

Initialize EC public key from public key string

Parameters:

Returns:

  • (OpenSSL:PKey::EC)

    OpenSSL public key instance

Since:

  • 0.1.0



55
56
57
58
59
# 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