Class: Izokatu::Rbnacl::PublicKey::Encrypter

Inherits:
Encrypter show all
Defined in:
lib/izokatu/rbnacl/public_key/encrypter.rb

Overview

RbNaCl public key encrypter

Constant Summary collapse

RBNACL_KEY_CLASSES =

RbNaCl public and private key classes

[
  RbNaCl::Boxes::Curve25519XSalsa20Poly1305::PrivateKey,
  RbNaCl::Boxes::Curve25519XSalsa20Poly1305::PublicKey
].freeze

Constants inherited from Encrypter

Encrypter::DEFAULT_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from Encrypter

#nonce

Attributes inherited from Encrypter

#clear_data, #encrypted_data, #encrypter

Instance Method Summary collapse

Methods inherited from Encrypter

#generate_nonce!

Methods inherited from Encrypter

#import_clear_data!, #perform

Methods included from Callable

#call

Constructor Details

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

Initializing option for encryption

Parameters:

Since:

  • 0.1.0



27
28
29
30
31
# File 'lib/izokatu/rbnacl/public_key/encrypter.rb', line 27

def initialize(public_key:, private_key:, clear_data:)
  @public_key = public_key
  @private_key = private_key
  super(clear_data: clear_data)
end

Instance Attribute Details

#private_keyRbNaCl::Boxes::Curve25519XSalsa20Poly1305::PrivateKey (readonly)

Returns private key.

Returns:

  • (RbNaCl::Boxes::Curve25519XSalsa20Poly1305::PrivateKey)

    private key



11
12
13
# File 'lib/izokatu/rbnacl/public_key/encrypter.rb', line 11

def private_key
  @private_key
end

#public_keyRbNaCl::Boxes::Curve25519XSalsa20Poly1305::PublicKey (readonly)

Returns public key.

Returns:

  • (RbNaCl::Boxes::Curve25519XSalsa20Poly1305::PublicKey)

    public key



9
10
11
# File 'lib/izokatu/rbnacl/public_key/encrypter.rb', line 9

def public_key
  @public_key
end

Instance Method Details

#create_encrypter!RbNaCl::Boxes::Curve25519XSalsa20Poly1305

Initializing option for encryption

Returns:

  • (RbNaCl::Boxes::Curve25519XSalsa20Poly1305)

    encrypter instance

Since:

  • 0.1.0



39
40
41
42
43
44
# File 'lib/izokatu/rbnacl/public_key/encrypter.rb', line 39

def create_encrypter!
  raise 'ERROR: No public key!' unless public_key
  raise 'ERROR: No private key!' unless private_key

  @encrypter = RbNaCl::Box.new(public_key, private_key)
end

#encrypt_data!Array

Encrypting data

Returns:

  • (Array)

    encrypted data with decrypter params

Since:

  • 0.1.0



52
53
54
55
56
57
# File 'lib/izokatu/rbnacl/public_key/encrypter.rb', line 52

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