Class: Izokatu::Openssl::PublicKey::RSA::Encrypter

Inherits:
Encrypter
  • Object
show all
Defined in:
lib/izokatu/openssl/public_key/rsa/encrypter.rb

Overview

OpenSSL public key RSA encrypter

Constant Summary

Constants inherited from Encrypter

Encrypter::DEFAULT_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from Encrypter

#clear_data, #encrypted_data, #encrypter

Instance Method Summary collapse

Methods inherited from Encrypter

#import_clear_data!, #perform

Methods included from Callable

#call

Constructor Details

#initialize(clear_data:, public_key:) ⇒ Encrypter

Initialize options for OpenSSL RSA encryption

Parameters:

Since:

  • 0.1.0



19
20
21
22
# File 'lib/izokatu/openssl/public_key/rsa/encrypter.rb', line 19

def initialize(clear_data:, public_key:)
  super(clear_data: clear_data)
  initialize_public_key!(public_key)
end

Instance Attribute Details

#public_keyString (readonly)

Returns public key string for decryption.

Returns:

  • (String)

    public key string for decryption



10
11
12
# File 'lib/izokatu/openssl/public_key/rsa/encrypter.rb', line 10

def public_key
  @public_key
end

Instance Method Details

#encrypt_data!Array (private)

Encrypting data

Returns:

  • (Array)

    encrypted data with empty hash in place of params

Since:

  • 0.1.0



46
47
48
49
50
# File 'lib/izokatu/openssl/public_key/rsa/encrypter.rb', line 46

def encrypt_data!
  raise 'ERROR: No public key!' unless public_key

  [{ encrypted_data_string: public_key.public_encrypt(clear_data) }, {}]
end

#initialize_public_key!(public_key) ⇒ OpenSSL:PKey::RSA

Initialize RSA public key from public key string

Parameters:

Returns:

  • (OpenSSL:PKey::RSA)

    OpenSSL public key instance

Since:

  • 0.1.0



32
33
34
35
36
# File 'lib/izokatu/openssl/public_key/rsa/encrypter.rb', line 32

def initialize_public_key!(public_key)
  raise 'ERROR: No public key!' unless public_key

  @public_key = OpenSSL::PKey::RSA.new(public_key)
end