Class: CryptoToolchain::BlackBoxes::CbcPaddingOracle

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key: Random.new.bytes(16), iv: Random.new.bytes(16)) ⇒ CbcPaddingOracle

Returns a new instance of CbcPaddingOracle.



7
8
9
10
11
12
# File 'lib/crypto_toolchain/black_boxes/cbc_padding_oracle.rb', line 7

def initialize(key: Random.new.bytes(16), iv: Random.new.bytes(16))
  @key = key
  @iv = iv
  @ciphertext = text.encrypt_cbc(key: key, iv: iv, blocksize: 16)
  @plaintext = text
end

Instance Attribute Details

#ciphertextObject (readonly)

Returns the value of attribute ciphertext.



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

def ciphertext
  @ciphertext
end

#plaintextObject (readonly)

Returns the value of attribute plaintext.



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

def plaintext
  @plaintext
end

Instance Method Details

#execute(str) ⇒ Object



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

def execute(str)
  begin
    !!str.
      decrypt_cbc(key: key, iv: iv, blocksize: 16, strip_padding: false).
      without_pkcs7_padding(16, raise_error: true)
  rescue ArgumentError
    false
  end
end