Class: Izokatu::Openssl::PublicKey::EC::Encrypter
- Defined in:
- lib/izokatu/openssl/public_key/ec/encrypter.rb
Overview
OpenSSL public key EC encrypter
Constant Summary collapse
- DEFAULT_ECIES_OPTIONS =
Default options for ECIES
{ ecies_cipher: 'AES-256-CTR', ecies_digest: 'SHA512', ecies_mac_length: :full, ecies_kdf_digest: 'SHA512', ecies_mac_digest: 'SHA512' }.freeze
Constants inherited from Encrypter
Instance Attribute Summary collapse
-
#ecies_cipher ⇒ String
readonly
ECIES cipher name.
-
#ecies_digest ⇒ String
readonly
ECIES digest name.
-
#ecies_kdf_digest ⇒ String
readonly
ECIES KDF digest name.
-
#ecies_mac_digest ⇒ String
readonly
ECIES MAC digest name.
-
#ecies_mac_length ⇒ Symbol
readonly
ECIES MAC length.
-
#public_key ⇒ String
readonly
Public key string for decryption.
Attributes inherited from Encrypter
#clear_data, #encrypted_data, #encrypter
Instance Method Summary collapse
-
#encrypt_data! ⇒ Array
private
Encrypting data.
-
#initialize(clear_data:, public_key:, ecies_options:) ⇒ Encrypter
constructor
Initialize options for OpenSSL EC encryption.
-
#initialize_ecies_options!(ecies_options) ⇒ Object
Initialize ECIES options.
-
#initialize_encrypter! ⇒ ECIES::Crypt
Initialize encrypter.
-
#initialize_public_key!(public_key) ⇒ OpenSSL:PKey::EC
Initialize EC public key from public key string.
Methods inherited from Encrypter
Methods included from Callable
Constructor Details
#initialize(clear_data:, public_key:, ecies_options:) ⇒ Encrypter
Initialize options for OpenSSL EC encryption
39 40 41 42 43 44 45 |
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 39 def initialize(clear_data:, public_key:, ecies_options:) super(clear_data: clear_data) @public_key = public_key initialize_public_key!(public_key) ( || DEFAULT_ECIES_OPTIONS) initialize_encrypter! end |
Instance Attribute Details
#ecies_cipher ⇒ String (readonly)
Returns ECIES cipher name.
12 13 14 |
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 12 def ecies_cipher @ecies_cipher end |
#ecies_digest ⇒ String (readonly)
Returns ECIES digest name.
14 15 16 |
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 14 def ecies_digest @ecies_digest end |
#ecies_kdf_digest ⇒ String (readonly)
Returns ECIES KDF digest name.
18 19 20 |
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 18 def ecies_kdf_digest @ecies_kdf_digest end |
#ecies_mac_digest ⇒ String (readonly)
Returns ECIES MAC digest name.
20 21 22 |
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 20 def ecies_mac_digest @ecies_mac_digest end |
#ecies_mac_length ⇒ Symbol (readonly)
Returns ECIES MAC length.
16 17 18 |
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 16 def ecies_mac_length @ecies_mac_length end |
#public_key ⇒ String (readonly)
Returns public key string for decryption.
10 11 12 |
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 10 def public_key @public_key end |
Instance Method Details
#encrypt_data! ⇒ Array (private)
Encrypting data
99 100 101 |
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 99 def encrypt_data! [{ encrypted_data_string: encrypter.encrypt(public_key, clear_data) }, {}] end |
#initialize_ecies_options!(ecies_options) ⇒ Object
Initialize ECIES options
67 68 69 70 71 72 73 |
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 67 def () @ecies_cipher = [:ecies_cipher] @ecies_digest = [:ecies_digest] @ecies_mac_length = [:ecies_mac_length] @ecies_kdf_digest = [:ecies_kdf_digest] @ecies_mac_digest = [:ecies_mac_digest] end |
#initialize_encrypter! ⇒ ECIES::Crypt
Initialize encrypter
81 82 83 84 85 86 87 88 89 |
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 81 def initialize_encrypter! @encrypter = ECIES::Crypt.new( cipher: ecies_cipher, digest: ecies_digest, mac_length: ecies_mac_length, kdf_digest: ecies_kdf_digest, mac_digest: ecies_mac_digest ) end |
#initialize_public_key!(public_key) ⇒ OpenSSL:PKey::EC
Initialize EC public key from public key string
55 56 57 58 59 |
# File 'lib/izokatu/openssl/public_key/ec/encrypter.rb', line 55 def initialize_public_key!(public_key) raise 'ERROR: No public key!' unless public_key @public_key = OpenSSL::PKey.read(public_key) end |