Class: Izokatu::Openssl::PrivateKey::Default::Decrypter

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

Overview

OpenSSL private key decrypter for non-authenticated ciphers

Direct Known Subclasses

Auth::Decrypter

Constant Summary collapse

DEFAULT_OPTIONS =

Default Openssl::PrivateKey::Default::Decrypter option

{
  cipher: 'AES256'
}.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:, cipher:, key:, nonce:) ⇒ Decrypter

Initialize options for OpenSSL EC decryption

Parameters:

Since:

  • 0.1.0



32
33
34
35
36
37
38
39
# File 'lib/izokatu/openssl/private_key/default/decrypter.rb', line 32

def initialize(encrypted_data:, cipher:, key:, nonce:)
  super(encrypted_data: encrypted_data)
  @cipher = cipher || DEFAULT_OPTIONS[:cipher]
  @key = key
  @nonce = nonce
  create_decrypter!
  initialize_decrypter_params!
end

Instance Attribute Details

#cipherString (readonly)

Returns OpenSSL private key cipher.

Returns:

  • (String)

    OpenSSL private key cipher



12
13
14
# File 'lib/izokatu/openssl/private_key/default/decrypter.rb', line 12

def cipher
  @cipher
end

#keyString (readonly)

Returns key for private key encryption/decryption.

Returns:

  • (String)

    key for private key encryption/decryption



14
15
16
# File 'lib/izokatu/openssl/private_key/default/decrypter.rb', line 14

def key
  @key
end

#nonceString (readonly)

Returns initialization vector for one-time use.

Returns:

  • (String)

    initialization vector for one-time use



16
17
18
# File 'lib/izokatu/openssl/private_key/default/decrypter.rb', line 16

def nonce
  @nonce
end

Instance Method Details

#create_decrypter!OpenSSL::Cipher (private)

Initializing decrypter

Returns:

  • (OpenSSL::Cipher)

    decrypter instance

Since:

  • 0.1.0



49
50
51
# File 'lib/izokatu/openssl/private_key/default/decrypter.rb', line 49

def create_decrypter!
  @decrypter = OpenSSL::Cipher.new(cipher).decrypt
end

#decrypt_data!Hash (private)

Decrypting data

Returns:

  • (Hash)

    decrypted data

Since:

  • 0.1.0



68
69
70
# File 'lib/izokatu/openssl/private_key/default/decrypter.rb', line 68

def decrypt_data!
  { decrypted_data_string: decrypter.update(encrypted_data) + decrypter.final }
end

#initialize_decrypter_params!Object (private)

Initializing decrypter params

Since:

  • 0.1.0



57
58
59
60
# File 'lib/izokatu/openssl/private_key/default/decrypter.rb', line 57

def initialize_decrypter_params!
  decrypter.key = key
  decrypter.iv = nonce
end