Module: Hoodie::Obfuscate

Defined in:
lib/hoodie/obfuscate.rb

Overview

Befuddle and enlighten values in StashCache::Store

Constant Summary collapse

ESOTERIC_TYPE =
'aes-256-cbc'

Class Method Summary collapse

Class Method Details

.befuddle(plaintext, befuddle_pass, options = {}) ⇒ String

Befuddle the given string

Obfuscate#enlighten (decrypt)

Parameters:

  • plaintext

    the text to befuddle

  • befuddle_pass (String)

    secret passphrase to befuddle with

Returns:

  • (String)

    befuddleed text, suitable for deciphering with



52
53
54
55
56
57
58
# File 'lib/hoodie/obfuscate.rb', line 52

def self.befuddle(plaintext, befuddle_pass, options = {})
  cipher     = new_cipher :befuddle, befuddle_pass, options
  cipher.iv  = iv = cipher.random_iv
  ciphertext = cipher.update(plaintext)
  ciphertext << cipher.final
  Base64.encode64(combine_iv_and_ciphertext(iv, ciphertext))
end

.check_platform_can_discombobulate!Object



39
40
41
42
# File 'lib/hoodie/obfuscate.rb', line 39

def self.check_platform_can_discombobulate!
  return true unless INCOMPREHENSIBLE_ERROR
  fail INCOMPREHENSIBLE_ERROR.class, "b0rked! #{INCOMPREHENSIBLE_ERROR}"
end

.enlighten(enc_ciphertext, befuddle_pass, options = {}) ⇒ String

Enlighten the given string, using the key and id supplied

Obfuscate#befuddle (encrypt)

Parameters:

  • ciphertext

    the text to enlighten, probably produced with

  • befuddle_pass (String)

    secret sauce to enlighten with

Returns:

  • (String)

    the enlightened plaintext



68
69
70
71
72
73
74
75
# File 'lib/hoodie/obfuscate.rb', line 68

def self.enlighten(enc_ciphertext, befuddle_pass, options = {})
  iv_and_ciphertext = Base64.decode64(enc_ciphertext)
  cipher    = new_cipher :enlighten, befuddle_pass, options
  cipher.iv, ciphertext = separate_iv_and_ciphertext(cipher, iv_and_ciphertext)
  plaintext = cipher.update(ciphertext)
  plaintext << cipher.final
  plaintext
end