Class: CryptoToolchain::BlackBoxes::CbcIvEqualsKeyTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/crypto_toolchain/black_boxes/cbc_iv_equals_key_target.rb

Instance Method Summary collapse

Constructor Details

#initialize(key: Random.new.bytes(16)) ⇒ CbcIvEqualsKeyTarget

Returns a new instance of CbcIvEqualsKeyTarget.



5
6
7
# File 'lib/crypto_toolchain/black_boxes/cbc_iv_equals_key_target.rb', line 5

def initialize(key: Random.new.bytes(16))
  @key = key
end

Instance Method Details

#encrypt(input) ⇒ Object



9
10
11
12
# File 'lib/crypto_toolchain/black_boxes/cbc_iv_equals_key_target.rb', line 9

def encrypt(input)
  str = prefix + input.gsub(/;|=/, "") + suffix
  str.encrypt_cbc(key: key, blocksize: 16, iv: key)
end

#is_admin?(crypted) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'lib/crypto_toolchain/black_boxes/cbc_iv_equals_key_target.rb', line 14

def is_admin?(crypted)
  dec = crypted.decrypt_cbc(key: key, blocksize: 16, iv: key)
  dec.each_byte do |byte|
    raise RuntimeError.new("Invalid byte in #{dec}") if byte > '~'.ord
  end
  dec.include?(";admin=true;")
end