class CryptoToolchain::BlackBoxes::CbcIvEqualsKeyTarget

Attributes

key[R]

Public Class Methods

new(key: Random.new.bytes(16)) click to toggle source
# File lib/crypto_toolchain/black_boxes/cbc_iv_equals_key_target.rb, line 5
def initialize(key: Random.new.bytes(16))
  @key = key
end

Public Instance Methods

encrypt(input) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

prefix() click to toggle source
# File lib/crypto_toolchain/black_boxes/cbc_iv_equals_key_target.rb, line 26
def prefix
  "comment1=cooking%20MCs;userdata="
end
suffix() click to toggle source
# File lib/crypto_toolchain/black_boxes/cbc_iv_equals_key_target.rb, line 30
def suffix
  ";comment2=%20like%20a%20pound%20of%20bacon"
end