class Izokatu::Openssl::PrivateKey::Default::Encrypter

OpenSSL private key encrypter for non-authenticated ciphers

Constants

DEFAULT_OPTIONS

Default Openssl::PrivateKey::Default::Encrypter option

Attributes

cipher[R]

@return [String] OpenSSL private key cipher

key[R]

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

nonce[R]

@return [String] initialization vector for one-time use

Public Class Methods

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

Initializing options for OpenSSL EC encryption

@param clear_data (clear_data) @param cipher (cipher)

@since 0.1.0

Calls superclass method Izokatu::Encrypter::new
# File lib/izokatu/openssl/private_key/default/encrypter.rb, line 28
def initialize(clear_data:, cipher:)
  super(clear_data: clear_data)
  @cipher = cipher || DEFAULT_OPTIONS[:cipher]
  create_encrypter!
  @key = encrypter.random_key
  @nonce = encrypter.random_iv
  initialize_encrypter_params!
end

Private Instance Methods

create_encrypter!() click to toggle source

Initializing encrypter

@return [OpenSSL::Cipher] encrypter instance

@since 0.1.0

# File lib/izokatu/openssl/private_key/default/encrypter.rb, line 45
def create_encrypter!
  @encrypter = OpenSSL::Cipher.new(cipher).encrypt
end
decrypter_params() click to toggle source

Returning decrypter params

@return [Hash] decrypter params

@since 0.1.1

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

Encrypting data

@return [Array] encrypted data with decrypter params

@since 0.1.0

# File lib/izokatu/openssl/private_key/default/encrypter.rb, line 65
def encrypt_data!
  [
    { encrypted_data_string: encrypter.update(clear_data) + encrypter.final },
    decrypter_params
  ]
end
initialize_encrypter_params!() click to toggle source

Initializing encrypter params

@since 0.1.0

# File lib/izokatu/openssl/private_key/default/encrypter.rb, line 53
def initialize_encrypter_params!
  # OpenSSL::Cipher instances has only key=, iv= and auth_data= methods
  encrypter.key = key
  encrypter.iv = nonce
end