Class: Izokatu::Rbnacl::PrivateKey::Encrypter
- Defined in:
- lib/izokatu/rbnacl/private_key/encrypter.rb
Overview
RbNaCl private key encrypter
Constant Summary
Constants inherited from Encrypter
Instance Attribute Summary collapse
-
#auth_data ⇒ String
readonly
Authenticated data.
-
#key ⇒ String
readonly
Key for private key encryption/decryption.
Attributes inherited from Encrypter
Attributes inherited from Encrypter
#clear_data, #encrypted_data, #encrypter
Instance Method Summary collapse
-
#create_encrypter! ⇒ Object
Generating encrypter instance from key.
-
#decrypter_params ⇒ Hash
Returning decrypter params.
-
#encrypt_data! ⇒ Array
Encrypting data.
-
#generate_key! ⇒ Object
Generating key.
-
#initialize(clear_data:, auth_data:) ⇒ Encrypter
constructor
Initializing option for encryption.
Methods inherited from Encrypter
Methods inherited from Encrypter
Methods included from Callable
Constructor Details
#initialize(clear_data:, auth_data:) ⇒ Encrypter
Initializing option for encryption
20 21 22 23 24 |
# 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 |
Instance Attribute Details
#auth_data ⇒ String (readonly)
Returns authenticated data.
11 12 13 |
# File 'lib/izokatu/rbnacl/private_key/encrypter.rb', line 11 def auth_data @auth_data end |
#key ⇒ String (readonly)
Returns key for private key encryption/decryption.
9 10 11 |
# File 'lib/izokatu/rbnacl/private_key/encrypter.rb', line 9 def key @key end |
Instance Method Details
#create_encrypter! ⇒ Object
Generating encrypter instance from key
38 39 40 |
# File 'lib/izokatu/rbnacl/private_key/encrypter.rb', line 38 def create_encrypter! @encrypter = RbNaCl::AEAD::XChaCha20Poly1305IETF.new(key) end |
#decrypter_params ⇒ Hash
Returning decrypter params
61 62 63 64 65 66 67 |
# File 'lib/izokatu/rbnacl/private_key/encrypter.rb', line 61 def decrypter_params { nonce: nonce, key: key, auth_data: auth_data } end |
#encrypt_data! ⇒ Array
Encrypting data
48 49 50 51 52 53 |
# 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! ⇒ Object
Generating key
30 31 32 |
# File 'lib/izokatu/rbnacl/private_key/encrypter.rb', line 30 def generate_key! @key = RbNaCl::Random.random_bytes(RbNaCl::SecretBox.key_bytes) end |