Class: Sekret::Decryptor

Inherits:
Object
  • Object
show all
Defined in:
lib/sekret/decryptor.rb

Overview

Handles decrypting a message

Author:

  • Maddie Schipper

Since:

  • 1.0.0

Defined Under Namespace

Classes: Payload

Instance Method Summary collapse

Constructor Details

#initialize(public_key, payload) ⇒ Decryptor

Create a new instance of Decryptor

Parameters:

  • public_key (String)

    The RSA public key used for decrypting the message. (Must be in pem format)

  • payload (String)

    The message payload

Since:

  • 1.0.0



26
27
28
29
# File 'lib/sekret/decryptor.rb', line 26

def initialize(public_key, payload)
  @key = OpenSSL::PKey::RSA.new(public_key)
  @raw_payload = payload
end

Instance Method Details

#callString

Perform the decryption

Returns:

  • (String)

Since:

  • 1.0.0



35
36
37
38
39
40
41
42
43
44
# File 'lib/sekret/decryptor.rb', line 35

def call
  payload = create_payload
  header = decrypt_raw_header(payload.header)
  case header.version
  when 1
    Sekret::BodyEncryption.decrypt(header, payload.body)
  else
    raise Sekret::Errors::UnsupportedVersionError, "Can't decrypt body with version: #{header.version}"
  end
end