Class: Izokatu::Openssl::PublicKey::RSA::Decrypter

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

Overview

OpenSSL public key RSA decrypter

Instance Attribute Summary collapse

Attributes inherited from Decrypter

#decrypted_data, #decrypter, #encrypted_data

Instance Method Summary collapse

Methods inherited from Decrypter

#import_encrypted_data!, #perform

Methods included from Callable

#call

Constructor Details

#initialize(encrypted_data:, private_key:) ⇒ Decrypter

Initialize options for OpenSSL RSA decryption

Parameters:

Since:

  • 0.1.0



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

def initialize(encrypted_data:, private_key:)
  super(encrypted_data: encrypted_data)
  initialize_private_key!(private_key)
end

Instance Attribute Details

#private_keyString (readonly)

Returns private key string for decryption.

Returns:

  • (String)

    private key string for decryption



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

def private_key
  @private_key
end

Instance Method Details

#decrypt_data!Hash (private)

Decrypting data

Returns:

  • (Hash)

    decrypted data

Since:

  • 0.1.0



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

def decrypt_data!
  { decrypted_data_string: private_key.private_decrypt(encrypted_data) }
end

#initialize_private_key!(private_key) ⇒ OpenSSL:PKey::RSA (private)

Initialize RSA private key from private key string

Parameters:

Returns:

  • (OpenSSL:PKey::RSA)

    OpenSSL private key instance

Since:

  • 0.1.0



34
35
36
37
38
# File 'lib/izokatu/openssl/public_key/rsa/decrypter.rb', line 34

def initialize_private_key!(private_key)
  raise 'ERROR: No private key!' unless private_key

  @private_key = OpenSSL::PKey.read(private_key)
end