Class: Ccs::Decrypter

Inherits:
Object
  • Object
show all
Defined in:
lib/ccs/decrypter.rb

Overview

Handles client-side decryption for documents.

The decrypter uses AES-256 in CBC mode internally. A salt is expected in bytes 8..15, with ciphertext occupying the further bytes.

Instance Method Summary collapse

Constructor Details

#initialize(passphrase, content) ⇒ Decrypter

Constructs a Decrypter instance with given passphrase and content.

Examples:

Ccs::Decrypter.new('the content passphrase', content)

Parameters:

  • passphrase (String)

    Passphrase for content decryption

  • content (String)

    Encrypted document content



17
18
19
20
# File 'lib/ccs/decrypter.rb', line 17

def initialize(passphrase, content)
  @passphrase = passphrase
  @content = content
end

Instance Method Details

#callString

Performs decryption, returning plaintext if passphrase matched.

Returns:

  • (String)

    Plaintext document content



25
26
27
28
29
# File 'lib/ccs/decrypter.rb', line 25

def call
  decryptor.pkcs5_keyivgen(@passphrase, ciphertext_salt, 1)
  result = decryptor.update(encrypted)
  result << decryptor.final
end