Class: Izokatu::Rbnacl::PrivateKey::Decrypter

Inherits:
Decrypter show all
Defined in:
lib/izokatu/rbnacl/private_key/decrypter.rb

Overview

RbNaCl private key decrypter

Constant Summary collapse

DEFAULT_OPTIONS =

Default options for Izokatu::Rbnacl::Decrypter

{
  auth_data: ''
}.freeze

Constants inherited from Decrypter

Decrypter::RBNACL_KEY_CLASSES

Instance Attribute Summary collapse

Attributes inherited from Decrypter

#nonce

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(key:, encrypted_data:, nonce:, auth_data:) ⇒ Decrypter

Initializing option for decryption

Parameters:

Since:

  • 0.1.0



28
29
30
31
32
# File 'lib/izokatu/rbnacl/private_key/decrypter.rb', line 28

def initialize(key:, encrypted_data:, nonce:, auth_data:)
  @key = key
  super(encrypted_data: encrypted_data, nonce: nonce)
  @auth_data = auth_data || DEFAULT_OPTIONS[:auth_data]
end

Instance Attribute Details

#auth_dataString (readonly)

Returns authenticated data.

Returns:

  • (String)

    authenticated data



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

def auth_data
  @auth_data
end

#keyString (readonly)

Returns key for private key encryption/decryption.

Returns:

  • (String)

    key for private key encryption/decryption



10
11
12
# File 'lib/izokatu/rbnacl/private_key/decrypter.rb', line 10

def key
  @key
end

Instance Method Details

#create_decrypter!RbNaCl::AEAD::XChaCha20Poly1305IETF

Creating decrypter instance

Returns:

  • (RbNaCl::AEAD::XChaCha20Poly1305IETF)

    decrypter instance

Since:

  • 0.1.0



40
41
42
# File 'lib/izokatu/rbnacl/private_key/decrypter.rb', line 40

def create_decrypter!
  @decrypter = RbNaCl::AEAD::XChaCha20Poly1305IETF.new(key)
end

#decrypt_data!Hash

Decrypting data

Returns:

  • (Hash)

    decrypted data

Since:

  • 0.1.0



50
51
52
# File 'lib/izokatu/rbnacl/private_key/decrypter.rb', line 50

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