class Izokatu::Rbnacl::PrivateKey::Encrypter

RbNaCl private key encrypter

Attributes

auth_data[R]

@return [String] authenticated data

key[R]

@return [String] key for private key encryption/decryption

Public Class Methods

new(clear_data:, auth_data:) click to toggle source

Initializing option for encryption

@param clear_data (clear_data) @param auth_data (auth_data)

@since 0.1.0

Calls superclass method Izokatu::Rbnacl::Encrypter::new
# File lib/izokatu/rbnacl/private_key/encrypter.rb, line 20
def initialize(clear_data:, auth_data:)
  generate_key!
  super(clear_data: clear_data)
  @auth_data = auth_data
end

Public Instance Methods

create_encrypter!() click to toggle source

Generating encrypter instance from key

@since 0.1.0

# File lib/izokatu/rbnacl/private_key/encrypter.rb, line 38
def create_encrypter!
  @encrypter = RbNaCl::AEAD::XChaCha20Poly1305IETF.new(key)
end
decrypter_params() click to toggle source

Returning decrypter params

@return [Hash] decrypter params

@since 0.1.1

# File lib/izokatu/rbnacl/private_key/encrypter.rb, line 61
def decrypter_params
  {
    nonce: nonce,
    key: key,
    auth_data: auth_data
  }
end
encrypt_data!() click to toggle source

Encrypting data

@return (Array) encrypted data with decrypter params

@since 0.1.0

# File lib/izokatu/rbnacl/private_key/encrypter.rb, line 48
def encrypt_data!
  [
    { encrypted_data_string: encrypter.encrypt(nonce, clear_data, auth_data) },
    decrypter_params
  ]
end
generate_key!() click to toggle source

Generating key

@since 0.1.0

# File lib/izokatu/rbnacl/private_key/encrypter.rb, line 30
def generate_key!
  @key = RbNaCl::Random.random_bytes(RbNaCl::SecretBox.key_bytes)
end