class CryptoToolbox::Oracles::PaddingOracle::MemoryOracle
Attributes
secret_plaintext[R]
Public Class Methods
new()
click to toggle source
# File lib/crypto-toolbox/oracles/padding_oracle/memory_oracle.rb, line 29 def initialize @key = SecureRandom.random_bytes(16) @iv = SecureRandom.random_bytes(16) @secret_plaintext = CryptBuffer.from_base64(PlaintextSelection::sample).str end
Public Instance Methods
connect()
click to toggle source
# File lib/crypto-toolbox/oracles/padding_oracle/memory_oracle.rb, line 39 def connect; end
disconnect()
click to toggle source
# File lib/crypto-toolbox/oracles/padding_oracle/memory_oracle.rb, line 40 def disconnect; end
sample_ciphertext()
click to toggle source
# File lib/crypto-toolbox/oracles/padding_oracle/memory_oracle.rb, line 35 def sample_ciphertext @ciphertext ||= generate_ciphertext end
valid_padding?(input,custom_block_amount=nil)
click to toggle source
# File lib/crypto-toolbox/oracles/padding_oracle/memory_oracle.rb, line 42 def valid_padding?(input,custom_block_amount=nil) # openssl will throw on invalid padding begin block = CryptBuffer(input) result = CryptBuffer(decrypt(block)) result.validate_padding! rescue CryptBufferConcern::Padding::InvalidPkcs7Padding => ex false end end
Private Instance Methods
check_padding(msg)
click to toggle source
# File lib/crypto-toolbox/oracles/padding_oracle/memory_oracle.rb, line 63 def check_padding(msg) end
decrypt(msg)
click to toggle source
# File lib/crypto-toolbox/oracles/padding_oracle/memory_oracle.rb, line 59 def decrypt(msg) Ciphers::Aes.new.decipher_cbc(@key,msg,iv: @iv,strip_padding: false) end
generate_ciphertext()
click to toggle source
# File lib/crypto-toolbox/oracles/padding_oracle/memory_oracle.rb, line 55 def generate_ciphertext CryptBuffer(@iv + Ciphers::Aes.new.encipher_cbc(@key,@secret_plaintext,iv: @iv).str).hex end