Class: Izokatu::Openssl::PublicKey::EC::Decrypter

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

Overview

OpenSSL public key EC decrypter

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

Instance Attribute Summary collapse

Attributes inherited from Decrypter

#decrypted_data, #decrypter, #encrypted_data

Instance Method Summary collapse

Methods inherited from Decrypter

#import_encrypted_data!, #perform

Methods included from Callable

#call

Constructor Details

#initialize(encrypted_data:, private_key:, ecies_options:) ⇒ Decrypter

Returns a new instance of Decrypter.



32
33
34
35
36
37
38
39
40
41
42
43
44
# 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

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/decrypter.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/decrypter.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/decrypter.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/decrypter.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/decrypter.rb', line 16

def ecies_mac_length
  @ecies_mac_length
end

#private_keyString (readonly)

Returns private key string for decryption.

Returns:

  • (String)

    private key string for decryption



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

def private_key
  @private_key
end

Instance Method Details

#decrypt_data!Hash (private)

Decrypting data

Returns:

  • (Hash)

    decrypted data

Since:

  • 0.1.0



98
99
100
# File 'lib/izokatu/openssl/public_key/ec/decrypter.rb', line 98

def decrypt_data!
  { decrypted_data_string: decrypter.decrypt(private_key, encrypted_data) }
end

#initialize_decrypter!ECIES::Crypt

Initialize decrypter

Returns:

  • (ECIES::Crypt)

    decrypter instance

Since:

  • 0.1.0



80
81
82
83
84
85
86
87
88
# 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) ⇒ Object

Initialize ECIES options

Parameters:

  • ecies_options

    Hash with ECIES options

Since:

  • 0.1.0



66
67
68
69
70
71
72
# 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) ⇒ OpenSSL:PKey::EC

Initialize EC private key from private key string

Parameters:

Returns:

  • (OpenSSL:PKey::EC)

    OpenSSL private key instance

Since:

  • 0.1.0



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