Class: Izokatu::Openssl::PrivateKey::Default::Encrypter
- Defined in:
- lib/izokatu/openssl/private_key/default/encrypter.rb
Overview
OpenSSL private key encrypter for non-authenticated ciphers
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_OPTIONS =
Default Openssl::PrivateKey::Default::Encrypter option
{ cipher: 'AES256' }.freeze
Instance Attribute Summary collapse
-
#cipher ⇒ String
readonly
OpenSSL private key cipher.
-
#key ⇒ String
readonly
Key for private key encryption/decryption.
-
#nonce ⇒ String
readonly
Initialization vector for one-time use.
Attributes inherited from Encrypter
#clear_data, #encrypted_data, #encrypter
Instance Method Summary collapse
-
#create_encrypter! ⇒ OpenSSL::Cipher
private
Initializing encrypter.
-
#decrypter_params ⇒ Hash
private
Returning decrypter params.
-
#encrypt_data! ⇒ Array
private
Encrypting data.
-
#initialize(clear_data:, cipher:) ⇒ Encrypter
constructor
Initializing options for OpenSSL EC encryption.
-
#initialize_encrypter_params! ⇒ Object
private
Initializing encrypter params.
Methods inherited from Encrypter
Methods included from Callable
Constructor Details
#initialize(clear_data:, cipher:) ⇒ Encrypter
Initializing options for OpenSSL EC encryption
28 29 30 31 32 33 34 35 |
# 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 |
Instance Attribute Details
#cipher ⇒ String (readonly)
Returns OpenSSL private key cipher.
10 11 12 |
# File 'lib/izokatu/openssl/private_key/default/encrypter.rb', line 10 def cipher @cipher end |
#key ⇒ String (readonly)
Returns key for private key encryption/decryption.
12 13 14 |
# File 'lib/izokatu/openssl/private_key/default/encrypter.rb', line 12 def key @key end |
#nonce ⇒ String (readonly)
Returns initialization vector for one-time use.
14 15 16 |
# File 'lib/izokatu/openssl/private_key/default/encrypter.rb', line 14 def nonce @nonce end |
Instance Method Details
#create_encrypter! ⇒ OpenSSL::Cipher (private)
Initializing encrypter
45 46 47 |
# File 'lib/izokatu/openssl/private_key/default/encrypter.rb', line 45 def create_encrypter! @encrypter = OpenSSL::Cipher.new(cipher).encrypt end |
#decrypter_params ⇒ Hash (private)
Returning decrypter params
78 79 80 |
# File 'lib/izokatu/openssl/private_key/default/encrypter.rb', line 78 def decrypter_params { nonce: nonce, key: key } end |
#encrypt_data! ⇒ Array (private)
Encrypting data
65 66 67 68 69 70 |
# 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! ⇒ Object (private)
Initializing encrypter params
53 54 55 56 57 |
# 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 |