pub fn encrypt(&self, plaintext: &[u8], iv: &[u8]) -> Result<Vec<u8>, PadbusterError> {
        info!("Starting Encrypt Mode");

        if plaintext.is_empty() {
            return Err(PadbusterError::ValidationError(
                "Cannot encrypt empty plaintext",
            ));
        }
        let mut pad = ((self.block_size as usize) - (plaintext.len() % (self.block_size as usize)))
            % (self.block_size as usize);
        if pad == 0 {
            pad = self.block_size as usize;
        }
        let mut used_iv = iv.to_owned();
        let mut ptext = plaintext.to_owned();
        let mut padding = vec![pad as u8; pad];
        ptext.append(&mut padding);

        info!("Attempting to encrypt {:?} bytes", ptext);
        if used_iv.is_empty() {
            used_iv = vec![0u8; self.block_size as usize];
        }
        let mut encrypted = used_iv;
        let mut block = encrypted.clone();

        let mut n = ptext.len();
        while n > 0 {
            info!("*** Starting Block {} ***", n / (self.block_size as usize));
            let intermediate_bytes = match self.bust(&mut block) {
                Err(e) => return Err(e),
                Ok(r) => r,
            };
            let current_intermediate_bytes = intermediate_bytes.clone();

            block = xor_data(
                intermediate_bytes,
                ptext[(n - (self.block_size as usize))..n].to_vec(),
            );
            let current_block = block.clone();

            let mut current_encrypted = encrypted.clone();
            encrypted = block.clone();
            encrypted.append(&mut current_encrypted);

            info!(
                "Block {} Results:
            [+] New Cipher Text (HEX): {}
            [+] Intermediate Bytes (HEX): {}",
                n / (self.block_size as usize),
                hex::encode(current_block),
                hex::encode(current_intermediate_bytes)
            );

            n -= self.block_size as usize;
        }

        info!(
            "*** Finished ***
        [+] Encrypted value is: {}",
            base64::encode(&encrypted)
        );

        Ok(encrypted)
    }
/// Encrypt the given plaintext & iv using oracle
///
/// # Arguments
///
/// * `plaintext` - Plaintext to use.
/// * `iv` - IV to use if known empty Vec<u8> if not.
///
Encrypt the given plaintext & iv using oracle
Encrypt the given plaintext & iv using oracle
pub fn encrypt(&self, plaintext: &[u8], iv: &[u8]) -> Result<Vec<u8>, PadbusterError> {
        info!("Starting Encrypt Mode");
        if plaintext.is_empty() {
            return Err(PadbusterError::ValidationError(
                "Cannot encrypt empty plaintext",
            ));
        }
        let mut pad = ((self.block_size as usize) - (plaintext.len() % (self.block_size as usize)))
            % (self.block_size as usize);
        if pad == 0 {
            pad = self.block_size as usize;
        }
        let mut used_iv = iv.to_owned();
        let mut ptext = plaintext.to_owned();
        let mut padding = vec![pad as u8; pad];
        ptext.append(&mut padding);
        info!("Attempting to encrypt {:?} bytes", ptext);
        if used_iv.is_empty() {
            used_iv = vec![0u8; self.block_size as usize];
        }
        let mut encrypted = used_iv;
        let mut block = encrypted.clone();
        let mut n = ptext.len();
        while n > 0 {
            info!("*** Starting Block {} ***", n / (self.block_size as usize));
            let intermediate_bytes = match self.bust(&mut block) {
                Err(e) => return Err(e),
                Ok(r) => r,
            };
            let current_intermediate_bytes = intermediate_bytes.clone();
            block = xor_data(
                intermediate_bytes,
                ptext[(n - (self.block_size as usize))..n].to_vec(),
            );
            let current_block = block.clone();
            let mut current_encrypted = encrypted.clone();
            encrypted = block.clone();
            encrypted.append(&mut current_encrypted);
            info!(
                "Block {} Results:
            [+] New Cipher Text (HEX): {}
            [+] Intermediate Bytes (HEX): {}",
                n / (self.block_size as usize),
                hex::encode(current_block),
                hex::encode(current_intermediate_bytes)
            );
            n -= self.block_size as usize;
        }
        info!(
            "*** Finished ***
        [+] Encrypted value is: {}",
            base64::encode(&encrypted)
        );
        Ok(encrypted)
    }
pub fn encrypt ( & self , plaintext : & [ u8 ] , iv : & [ u8 ] ) -> Result < Vec < u8 > , PadbusterError > { info ! ( " " ) ; if plaintext . is_empty ( ) { return Err ( PadbusterError :: ValidationError ( " " , ) ) ; } let mut pad = ( ( self . block_size as usize ) - ( plaintext . len ( ) % ( self . block_size as usize ) ) ) % ( self . block_size as usize ) ; if pad == 0 { pad = self . block_size as usize ; } let mut used_iv = iv . to_owned ( ) ; let mut ptext = plaintext . to_owned ( ) ; let mut padding = vec ! [ pad as u8 pad ] ; ptext . append ( & mut padding ) ; info ! ( " " ptext ) ; if used_iv . is_empty ( ) { used_iv = vec ! [ 0u8 self block_size as usize ] ; } let mut encrypted = used_iv ; let mut block = encrypted . clone ( ) ; let mut n = ptext . len ( ) ; while n > 0 { info ! ( " " n ( self block_size as usize ) ) ; let intermediate_bytes = match self . bust ( & mut block ) { Err ( e ) => return Err ( e ) , Ok ( r ) => r , } ; let current_intermediate_bytes = intermediate_bytes . clone ( ) ; block = xor_data ( intermediate_bytes , ptext [ ( n - ( self . block_size as usize ) ) .. n ] . to_vec ( ) , ) ; let current_block = block . clone ( ) ; let mut current_encrypted = encrypted . clone ( ) ; encrypted = block . clone ( ) ; encrypted . append ( & mut current_encrypted ) ; info ! ( " " n ( self block_size as usize ) hex encode ( current_block ) hex encode ( current_intermediate_bytes ) ) ; n -= self . block_size as usize ; } info ! ( " " base64 encode ( encrypted ) ) ; Ok ( encrypted ) }
Encrypt the given plaintext & iv using oracle
Encrypt the given plaintext & iv using oracle
&self
plaintext
&[u8]
iv
&[u8]
&self
plaintext
&[u8]
iv
&[u8]